SYSUTCDATETIME() Examples in SQL Server (T-SQL)

In SQL Server, the T-SQL SYSUTCDATETIME() function is used to return the current UTC time (Coordinated Universal Time). UTC time is the primary time standard by which the world regulates clocks and time.

The return value of the SYSUTCDATETIME() function is derived from the computer on which the instance of SQL Server is running. The time zone is not included, and it is returned as a datetime2 value. The fractional second precision specification has a range from 1 to 7 digits. The default precision is 7 digits.

SYSUTCDATETIME() does the same thing that GETUTCDATE() does, except that it returns a higher fractional precision. As mentioned,  SYSUTCDATETIME() returns a datetime2 value, whereas the GETUTCDATE() function returns a datetime value.

Syntax

The syntax goes like this:

SYSUTCDATETIME ( )

So this function doesn’t accept any arguments.

Example

Here’s an example of usage:

SELECT SYSUTCDATETIME() AS Result;

Result:

+-----------------------------+
| Result                      |
|-----------------------------|
| 2018-06-17 22:44:32.4094671 |
+-----------------------------+

Formatting the Date

You can always use other T-SQL functions along with SYSUTCDATETIME(). For example, you can use the FORMAT() function to format the date into the format you require (and have it returned as a string).

Example:

 
SELECT FORMAT(SYSUTCDATETIME(), 'dddd, dd MMMM yyyy, hh:mm tt') AS Result;

Result:

+--------------------------------+
| Result                         |
|--------------------------------|
| Sunday, 17 June 2018, 10:45 PM |
+--------------------------------+

Variable Assignment

Note that SYSUTCDATETIME() can be assigned to a variable of any one of the date and time types.

Example:

DECLARE @date date = SYSUTCDATETIME(); 
DECLARE @time time = SYSUTCDATETIME(); 
SELECT 
    @date AS 'UTC Date', 
    @time AS 'UTC Time';

Result:

+------------+------------------+
| UTC Date   | UTC Time         |
|------------+------------------|
| 2018-06-17 | 22:48:43.4380954 |
+------------+------------------+