The SQL GETDATE function returns the current timestamp of the database as a datetime value.
The current timestamp derives from the operating system on which the SQL server is running. The GetDATE function returns the timestamp in the format YYYY-MM-DD hh:mm:ss:mmm.
SQL GETDATE Usage Notes
The return data type of the GETDATE function is datetime. Use the function anywhere a datetime expression is expected. The GETDATE function is nondeterministic. It returns a different value that is the current date and time whenever it runs, although the database state remains the same. Therefore, you can not index columns that reference GETDATE.
SQL GETDATE Examples
The following example returns the current date and time of the operating system on which the SQL server instance is running.
/* Answer */ SELECT GETDATE() system_current_date_time;
SELECT GETDATE() system_current_date_time;
The output is a complete timestamp.
We can use the Convert or the Cast function to keep only the date or the time part.
Here is we get the date:
/* Answer */ SELECT CONVERT(date, GETDATE()) currentDate; SELECT CAST(GETDATE() AS date) currentDate;
And here we convert GETDATE into the current time.
/* Answer */ SELECT CONVERT(time, GETDATE()) currentTime; SELECT CAST(GETDATE() AS time) currentTime;