SQL Server Get UTC Date

As a database developer, I’ve found that handling time zones correctly is essential. In this comprehensive article, I’ll walk you through everything you need to know about working with UTC dates in SQL Server.

SQL Server Get UTC Date

Let’s discuss all the approaches for retrieving the UTC date in SQL Server.

Approach-1: Using GETUTCDATE() Function

The most fundamental function for working with UTC dates in SQL Server is GETUTCDATE(), which returns the current UTC date and time as a DATETIME data type.

This function does not accept any parameters and always returns the current system’s UTC date and time.

We can execute the following query for this purpose.

SELECT GETUTCDATE() AS CurrentUTCDateTime;

After executing the above query, I got the expected output as shown in the screenshot below.

SQL Server Get UTC Date

When working with UTC dates, you’ll frequently need to convert between UTC and local time zones.

Approach-2: Using DATEADD with Time Zone Offset

The following query can be used to convert UTC to Eastern Time (EST/EDT).

SELECT 
    GETUTCDATE() AS UTCDateTime,
    DATEADD(HOUR, -5, GETUTCDATE()) AS EasternStandardTime

After executing the above query, I got the expected output as shown in the screenshot below.

how to get utc date in sql server

Approach-3: Using AT TIME ZONE

This method works for SQL Server 2016+ versions. We can use the following query for this purpose.

SELECT 
    GETUTCDATE() AS UTCDateTime,
    GETUTCDATE() AT TIME ZONE 'UTC' AT TIME ZONE 'Eastern Standard Time' AS EasternTime

After executing the above query, I got the expected output as shown in the screenshot below.

get utc date sql server

Formatting UTC Dates

When displaying dates to users, formatting them appropriately becomes important. We can use the following query for this purpose. This will format UTC date for US format display.

SELECT FORMAT(GETUTCDATE(), 'MM/dd/yyyy hh:mm:ss tt') AS FormattedUTCDate;

After executing the above query, I got the expected output as shown in the screenshot below.

get utc date in sql server

UTC Date Functions Reference Table

FunctionPurposeSQL Server Version
GETUTCDATE()Returns current UTC date/timeAll versions
SYSUTCDATETIME()Returns current UTC with higher precisionSQL 2008+
AT TIME ZONEConverts between time zonesSQL 2016+
TODATETIMEOFFSETConverts to DATETIMEOFFSET typeSQL 2008+

Conclusion

Working with UTC dates in SQL Server is critical for working with global applications. By following the approaches outlined in this article, you can easily implement this in your application. Hope this will help you !!

You may also like the following articles.