SQL Server GETDATE() Function
GETDATE() returns the current date and time from the SQL Server system clock as a datetime value. It does not include a time-zone offset. CURRENT_TIMESTAMP is its ANSI SQL synonym and is written without parentheses. Both have less fractional-second precision than SYSDATETIME(). Azure SQL Database (except Managed Instance) and Azure Synapse use UTC, so GETDATE() returns a UTC clock value in those services, still without an offset. See Microsoft’s GETDATE documentation and CURRENT_TIMESTAMP documentation.
Syntax
GETDATE()
Usage
Use GETDATE() or CURRENT_TIMESTAMP when the server’s current date/time in datetime format is sufficient:
- To obtain the current date and timestamp
- To insert the current date/time into a
datetimecolumn
Examples
Example 1
Assuming there is a table named orders with a timestamp column named order_time. To set the order_time column to the current timestamp when inserting new rows into the table, use the following SQL query:
INSERT INTO orders (order_id, order_time, customer_id)
VALUES (12345, GETDATE(), 789);
After executing the query, the order_time column will contain the current date and timestamp.
Example 2
Assuming you want to add a column named timestamp to the query result that contains the current timestamp. Use the following SQL query:
SELECT order_id, customer_id, order_total, GETDATE() AS current_datetime
FROM orders;
The result set contains a current_datetime column. For current UTC time, use GETUTCDATE() or SYSUTCDATETIME(); for the current system offset, use SYSDATETIMEOFFSET().
Conclusion
SQL Server’s timestamp data type is a deprecated synonym for rowversion, not a date/time type. Use a datetime or datetime2 column for dates. See Microsoft’s date and time types.