SQL SYSDATETIMEOFFSET() returns a value that represents the current system date and time, including the computer’s time zone on which the SQL Server instance is running. The datatype returned is of DATETIMEOFFSET (7) type.
SQL SYSDATETIMEOFFSET()
SQL SYSDATETIMEOFFSET() is a built-in function that returns a datetimeoffset(7) value that contains the date and time of the computer on which the instance of SQL Server is running. In addition, the time zone offset is included.
Syntax
SELECT SYSDATETIMEOFFSET();
Examples
Query 1
Get the current system date and time with the server’s time zone.
SELECT SYSDATETIMEOFFSET();
Output
2019-11-30 08:56:48.0645108 +07:00
Query 2
Using the DATEPART() function to return the timezone offset.
SELECT SYSDATETIMEOFFSET () AS [System DateTime Offset], DATEPART (TZoffset, SYSDATETIMEOFFSET ()) AS [Timezone Offset];
Output
System DateTime Offset | Timezone Offset |
2019-11-30 08:56:48.0645108 +07:00 | 420 |
Explanation
DATEPART() function returned an integer representing the time zone offset in minutes.
Query 3
Using FORMAT() function to format the timezone offset.
SELECT SYSDATETIMEOFFSET () AS 'System Date Time Offset', FORMAT (SYSDATETIMEOFFSET (), 'ss') AS 'ss', FORMAT (SYSDATETIMEOFFSET (), 'sss') AS 'sss';
Output
System Date Time Offset | ss | sss |
2019-11-30 08:56:48.0645108 +07:00 | +07 | +07:00 |