SQL Server SYSDATETIME() Function
The SYSDATETIME()
function in SQL Server retrieves the current date and time from the server's system clock. This is invaluable for logging events, creating timestamps in your database, or for any application that requires the server's current date and time.
SYSDATETIME(): Definition and Usage
SYSDATETIME()
provides a precise timestamp, reflecting the time on the server where your SQL Server database is running. It's important to understand that this time is based on the server's clock and might differ from the client machine's clock.
Syntax
Syntax
SYSDATETIME()
Return Type
The function returns a datetime2(7)
value.
Example
Getting the Server's Current Date and Time
This query gets the current date and time from the SQL Server instance.
Syntax
SELECT SYSDATETIME() AS SysDateTime;
Output
SysDateTime
-----------------------
2024-11-06 15:36:22.1234567 (Example; the exact time will vary)
Technical Details
The SYSDATETIME()
function is available in:
- SQL Server (starting with version 2008)
- Azure SQL Database
- Azure SQL Data Warehouse
- Parallel Data Warehouse