Dofactory.com
Dofactory.com
Earn income with your data and sql skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

SQL SYSDATETIMEOFFSET Function

SYSDATETIMEOFFSET returns the current datetime with timezone on the database server.

This function can be used as default value for DATETIMEOFFSET and DATETIME columns.

Example

#

The example returns the current datetime with timezone offset on the database server.

SELECT SYSDATETIMEOFFSET() AS 'Now'
Result:  1 record
Now
2023-12-21 16:23:45.8385649 -06:00

Syntax

Syntax of the SYSDATETIMEOFFSET function.

SYSDATETIMEOFFSET()

System Datetime

SQL Server supports 6 system datetime functions.

 SELECT CURRENT_TIMESTAMP AS 'CURRENT_TIMESTAMP',
        SYSDATETIME() AS 'SYSDATETIME',
        SYSDATETIMEOFFSET() AS 'SYSDATETIMEOFFSET',  
        SYSUTCDATETIME() AS 'SYSUTCDATETIME', 
        GETDATE() AS 'GETDATE',
        GETUTCDATE() AS 'GETUTCDATE'
Result:
Function Result
CURRENT_TIMESTAMP 2021-09-12 18:14:15.007
SYSDATETIME() 2021-09-12 18:14:15.0077586
SYSDATETIMEOFFSET() 2021-09-12 18:14:15.0077586 -05:00
SYSUTCDATETIME() 2021-09-12 23:14:15.0077586
GETDATE() 2021-09-12 18:14:15.007
GETUTCDATE() 2021-09-12 23:14:15.007

The results differ in microsecond precision and datetime offset values.


You may also like



Last updated on Dec 21, 2023

Earn income with your data and sql skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.