SQL Server SYSDATETIME() Function
Updated on
SYSDATETIME() returns the current date and time from the SQL Server system clock as datetime2(7). Its fractional-second precision is 100 nanoseconds, but actual clock accuracy depends on the operating system and hardware. The value has no time-zone offset. See Microsoft’s SYSDATETIME documentation.
Syntax
SYSDATETIME()
Examples
Read the value or store it in a column with matching precision:
SELECT SYSDATETIME() AS current_datetime;
CREATE TABLE dbo.AuditEvents (
event_id bigint PRIMARY KEY,
created_at datetime2(7) NOT NULL
);
INSERT INTO dbo.AuditEvents (event_id, created_at)
VALUES (1, SYSDATETIME());
SYSDATETIME() returns a datetime2(7), unlike GETDATE(), which returns datetime. For UTC without an offset, use SYSUTCDATETIME(). To include the system’s current offset, use SYSDATETIMEOFFSET().