SQL Server GETUTCDATE Function

Summary: in this tutorial, you will learn how to use the SQL Server GETUTCDATE() function to get the current UTC time.

SQL Server GETUTCDATE() function overview

The GETUTCDATE() function returns the current UTC time. The GETUTCDATE() function calculates this value from the operating system on which the SQL server is running.

The GETUTCDATE() function has the following syntax:

GETUTCDATE()
Code language: SQL (Structured Query Language) (sql)

This function returns the DATETIME value that represents the current UTC timestamp.

SQL Server GETUTCDATE() example

This example uses the GETDATE(), GETUTCDATE() and DATEDIFF() functions to return the local time, UTC time, and server time zone:

DECLARE 
    @local_time DATETIME,
    @utc_time DATETIME;

SET @local_time = GETDATE();
SET @utc_time = GETUTCDATE();

SELECT 
    CONVERT(VARCHAR(40), @local_time) 
        AS 'Server local time';
SELECT 
    CONVERT(VARCHAR(40), @utc_time) 
        AS 'Server UTC time'
SELECT 
    CONVERT(VARCHAR(40), DATEDIFF(hour, @utc_time, @local_time)) 
        AS 'Server time zone';
GO
Code language: SQL (Structured Query Language) (sql)

In this example, you have learned how to use the SQL Server GETUTCDATE() function to get the current UTC time.

Was this tutorial helpful?