Summary: in this tutorial, you will learn how to use the SYSUTCDATETIME()
function to get the current system date and time as UTC time.
SQL Server SYSUTCDATETIME() function
The SYSUTCDATETIME()
function returns a value of DATETIME2
that represents the current system date and time of the server on which the SQL Server instance is running. The datetime is in Coordinated Universal Time (UTC).
Here is the syntax of the SYSUTCDATETIME()
function:
SYSDATETIME()
Code language: SQL (Structured Query Language) (sql)
For example, to get the current date and time in UTC you use the following statement:
SELECT
SYSUTCDATETIME() utc_time;
Code language: SQL (Structured Query Language) (sql)
The output is as follows:
2019-05-03 00:50:06.1821224
Code language: SQL (Structured Query Language) (sql)
Notice that the SYSUTCDATETIME()
function has more fractional seconds precision than the GETUTCDATE()
function.
SQL Server SYSUTCDATETIME() function examples
A) Returning the current system date as UTC time example
The following example uses the CONVERT()
function to convert the result of the SYSUTCDATETIME()
function to the current date as UTC time:
SELECT
CONVERT(DATE, SYSUTCDATETIME()) utc_date;
Code language: SQL (Structured Query Language) (sql)
Here is the result:
utc_date
----------
2019-05-03
(1 row affected)
Code language: SQL (Structured Query Language) (sql)
B) Returning the current system time as UTC time example
This example converts the result of the SYSUTCDATETIME()
function to the current date as UTC time:
SELECT
CONVERT(DATE, SYSUTCDATETIME()) utc_time;
Code language: SQL (Structured Query Language) (sql)
The following shows the output:
utc_time
----------
2019-05-03
(1 row affected)
Code language: SQL (Structured Query Language) (sql)
In this tutorial, you have learned how to use the SQL Server SYSUTCDATETIME()
function to get the current system date and time as UTC time.