SQL SYSUTCDATETIME() Function: Complete Guide

SQL SYSUTCDATETIME() returns the datetime2 value that contains a date and time of a computer on which an instance of SQL Server is running.

SQL SYSUTCDATETIME()

SQL SYSUTCDATETIME() is a built-in Date function used to return the Current Date and Time of the system, i.e., DATETIME2 on which the SQL Server instance is running. The DATETIME is in coordinated Universal Time (UTC). The format is: ‘yyyy-mm-dd hh:mm:ss.nnnnnnn’.

The date and time are returned as UTC time (Coordinated Universal Time). The fractional second precision specification has the range from 1 to 7 digits. The default precision is 7 digits.

Syntax

SELECT SYSUTCDATETIME();

Note

  1. The function is similar to the GETUTCDATE () function having some differences.
  2. SYSUTCDATETIME returns the fractional seconds precision up to 7, whereas the GETUTCDATE returns the fractional seconds precision up to 3.
  3. SYSUTCDATETIME returns datetime2 as the data type, whereas the GETUTCDATE returns DateTime as the data type.
  4. The function is a non-deterministic type; therefore, views and columns that have expressions reference this function cannot be indexed.

Examples

Query 1

SELECT SYSUTCDATETIME () AS CURRENT_DATE;

Output

CURRENT_DATE
2019-11-25 14:55:33.3975855

 

Query 2

Using CONVERT () function to convert SYSUTCDATETIME function to Current Date.

SELECT CONVERT (DATE, SYSUTCDATETIME ());

Output

2019-11-25

Query 3

Using CONVERT () function to convert SYSUTCDATETIME function to Current Time.

SELECT CONVERT (TIME, SYSUTCDATETIME ());

Output

15:08:33.3975855

Query 4

Using the DATEPART() function to display MilliSeconds, Micro Seconds and Nano Seconds.

Queries

SELECT 'Milli Seconds' AS 'MILLISECOND', DATEPART (millisecond, SYSUTCDATETIME ()) AS [ MilliSeconds_Value]; 

SELECT 'Micro Seconds' AS 'MICROSECOND', DATEPART (microsecond, SYSUTCDATETIME ()) AS [MicroSeconds_Value]; 

SELECT 'Nano Seconds' AS 'NANOSECOND', DATEPART (nanosecond, SYSUTCDATETIME ()) AS [NanoSeconds_Value];

Output

MILLISECOND MilliSeconds_Value
Milli Seconds 397

 

MICROSECOND MicroSeconds_Value
Micro Seconds 397585

 

NANOSECONDS NanoSeconds_Value
Nano Seconds 39758500

 

Query 5

Using the DATENAME() function to display Weekday name from Current Date and Time.

SELECT 'Day' AS 'DAY', DATENAME (WEEKDAY, SYSUTCDATETIME ()) AS [Day_Name]; 

Output

DAY Day_Name
Day Monday

Query 6

SELECT 'Tomorrow' AS 'DAY', DATEADD (day, 1, SYSUTCDATETIME ()) AS [Next_Date];

Output

DAY Next_Date
Tomorrow 2019-11-26 14:55:33.3975855

See also

SQL Date

SQL GETUTCDATE()

SQL GETDATE()

SQL SYSDATETIME()

SQL CURRENT_TIME()

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.