The SQL GETDATE function returns the current timestamp of the database as a datetime value.
Description
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.
Syntax
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.
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:
And here we convert GETDATE into the current time.