Menu

SQL Server SYSDATETIMEOFFSET() Function

Updated on

SYSDATETIMEOFFSET() returns the current date and time from the SQL Server system clock as datetimeoffset(7), including the system’s current numeric UTC offset. It does not return a time-zone name or the full rules for a named time zone. Azure SQL Database (except Azure SQL Managed Instance) and Azure Synapse Analytics use UTC system time. See Microsoft’s SYSDATETIMEOFFSET documentation.

Syntax

SYSDATETIMEOFFSET()

Store a system timestamp with its offset

Use a datetimeoffset column when the numeric offset should travel with the value:

CREATE TABLE dbo.AuditEvents (
    event_id bigint PRIMARY KEY,
    created_at datetimeoffset(7) NOT NULL
);

INSERT INTO dbo.AuditEvents (event_id, created_at)
VALUES (1, SYSDATETIMEOFFSET());

The stored value contains an offset such as -07:00, but not an identifier such as Pacific Standard Time. To interpret a local value using a named zone’s daylight-saving rules, use AT TIME ZONE. For the current UTC date/time without an offset, use SYSUTCDATETIME().