Επεξεργασία

SYSDATETIME (Transact-SQL)

Applies to: SQL Server Azure SQL Database Azure SQL Managed Instance Azure Synapse Analytics SQL analytics endpoint in Microsoft Fabric Warehouse in Microsoft Fabric SQL database in Microsoft Fabric

The SYSDATETIME Transact-SQL (T-SQL) function returns a datetime2(7) value that contains the date and time of the computer on which the instance of SQL Server is running.

Note

SYSDATETIME and SYSUTCDATETIME have more fractional seconds precision than GETDATE and GETUTCDATE. SYSDATETIMEOFFSET includes the system time zone offset. SYSDATETIME, SYSUTCDATETIME, and SYSDATETIMEOFFSET can be assigned to a variable of any of the date and time types.

Azure Synapse Analytics follows UTC. Use AT TIME ZONE in Azure Synapse Analytics if you need to interpret date and time information in a non-UTC time zone.

Note

Azure SQL Database and SQL database in Microsoft Fabric support changing the default time zone from universal coordinated time (UTC). If you modify the time zone at the database or session level, this function returns local time based on the configured time zone value. For more information, see ALTER DATABASE SCOPED CONFIGURATION and SET TIME ZONE.

See Date and time data types and functions for an overview of all the Transact-SQL date and time data types and functions.

Transact-SQL syntax conventions

Syntax

SYSDATETIME ( )

Return types

datetime2(7)

Remarks

Transact-SQL statements can refer to SYSDATETIME anywhere they can refer to a datetime2(7) expression.

SYSDATETIME is a nondeterministic function. You can't index views and expressions that reference this function in a column.

Note

SQL Server gets the date and time values by using the GetSystemTimeAsFileTime() Windows API. The accuracy depends on the computer hardware and version of Windows on which the instance of SQL Server is running. The precision of this API is fixed at 100 nanoseconds. You can use the GetSystemTimeAdjustment() Windows API to determine the accuracy.

Examples

The following examples use the six SQL Server system functions that return current date and time to return the date, time, or both. The values are returned in series; therefore, their fractional seconds might be different.

In these examples, assume that the current date is April 30, 2026.

A. Get the current system date and time

SELECT SYSDATETIME(),
       SYSDATETIMEOFFSET(),
       SYSUTCDATETIME(),
       CURRENT_TIMESTAMP,
       GETDATE(),
       GETUTCDATE(),
       CURRENT_DATE;

Here's the result set.

SYSDATETIME()        2026-09-01 16:15:37.7418724
SYSDATETIMEOFFSET()  2026-09-01 16:15:37.7418724 -06:00
SYSUTCDATETIME()     2026-09-01 22:15:37.7418724
CURRENT_TIMESTAMP    2026-09-01 16:15:37.740
GETDATE()            2026-09-01 16:15:37.740
GETUTCDATE()         2026-09-01 22:15:37.740
CURRENT_DATE         2026-09-01

B. Get the current system date

The following example shows you how to convert date and time values to the date data type.

SELECT CONVERT (DATE, SYSDATETIME()),
       CONVERT (DATE, SYSDATETIMEOFFSET()),
       CONVERT (DATE, SYSUTCDATETIME()),
       CONVERT (DATE, CURRENT_TIMESTAMP),
       CONVERT (DATE, GETDATE()),
       CONVERT (DATE, GETUTCDATE()),
       CURRENT_DATE;

Here's the result set.

SYSDATETIME()        2026-09-01
SYSDATETIMEOFFSET()  2026-09-01
SYSUTCDATETIME()     2026-09-01
CURRENT_TIMESTAMP    2026-09-01
GETDATE()            2026-09-01
GETUTCDATE()         2026-09-01
CURRENT_DATE         2026-09-01

C. Get the current system time

SELECT CONVERT (TIME, SYSDATETIME()),
       CONVERT (TIME, SYSDATETIMEOFFSET()),
       CONVERT (TIME, SYSUTCDATETIME()),
       CONVERT (TIME, CURRENT_TIMESTAMP),
       CONVERT (TIME, GETDATE()),
       CONVERT (TIME, GETUTCDATE());

Here's the result set.

SYSDATETIME()        16:15:37.7418724
SYSDATETIMEOFFSET()  16:15:37.7418724
SYSUTCDATETIME()     22:15:37.7418724
CURRENT_TIMESTAMP    16:15:37.740
GETDATE()            16:15:37.740
GETUTCDATE()         22:15:37.740

Examples: Azure Synapse Analytics

D. Get the current system date and time

SELECT SYSDATETIME();

Here's the result set.

--------------------------
4/30/2026 1:10:02 PM