Any suggestions? Export (0) Print
Expand All

SYSDATETIMEOFFSET (Transact-SQL)

 

THIS TOPIC APPLIES TO:yesSQL Server (starting with 2008) yesAzure SQL Database yesAzure SQL Data Warehouse yesParallel Data Warehouse

Returns a datetimeoffset(7) value that contains the date and time of the computer on which the instance of SQL Server is running. The time zone offset is included.

For an overview of all Transact-SQL date and time data types and functions, see Date and Time Data Types and Functions (Transact-SQL).

Topic link icon Transact-SQL Syntax Conventions


SYSDATETIMEOFFSET ( )
-- Azure SQL Data Warehouse and Parallel Data Warehouse
SYSDATETIMEOFFSET ()

datetimeoffset(7)

Transact-SQL statements can refer to SYSDATETIMEOFFSET anywhere they can refer to a datetimeoffset expression.

SYSDATETIMEOFFSET is a nondeterministic function. Views and expressions that reference this function in a column cannot be indexed.

System_CAPS_noteNote

SQL Server obtains 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. The accuracy can be determined by using the GetSystemTimeAdjustment() Windows API.

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.

The following example shows the different formats that are returned by the date and time functions.

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

Here is the result set.

SYSDATETIME() 2007-04-30 13:10:02.0474381

SYSDATETIMEOFFSET()2007-04-30 13:10:02.0474381 -07:00

SYSUTCDATETIME() 2007-04-30 20:10:02.0474381

CURRENT_TIMESTAMP 2007-04-30 13:10:02.047

GETDATE() 2007-04-30 13:10:02.047

GETUTCDATE() 2007-04-30 20:10:02.047

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

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

Here is the result set.

2007-04-30

2007-04-30

2007-04-30

2007-04-30

2007-04-30

2007-04-30

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

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

Here is the result set.

SYSDATETIME() 13:18:45.3490361

SYSDATETIMEOFFSET()13:18:45.3490361

SYSUTCDATETIME() 20:18:45.3490361

CURRENT_TIMESTAMP 13:18:45.3470000

GETDATE() 13:18:45.3470000

GETUTCDATE() 20:18:45.3470000

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.

The following example shows the different formats that are returned by the date and time functions.

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

Here is the result set.

SYSDATETIME() 2007-04-30 13:10:02.0474381

SYSDATETIMEOFFSET()2007-04-30 13:10:02.0474381 -07:00

SYSUTCDATETIME() 2007-04-30 20:10:02.0474381

CURRENT_TIMESTAMP 2007-04-30 13:10:02.047

GETDATE() 2007-04-30 13:10:02.047

GETUTCDATE() 2007-04-30 20:10:02.047

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

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

Here is the result set.

2007-04-30

2007-04-30

2007-04-30

2007-04-30

2007-04-30

2007-04-30

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

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

Here is the result set.

SYSDATETIME() 13:18:45.3490361

SYSDATETIMEOFFSET()13:18:45.3490361

SYSUTCDATETIME() 20:18:45.3490361

CURRENT_TIMESTAMP 13:18:45.3470000

GETDATE() 13:18:45.3470000

GETUTCDATE() 20:18:45.3470000

Community Additions

ADD
Show:
© 2016 Microsoft