SQL SERVER – Convert Date Time AT TIME ZONE

I received an interesting question from my client last week about Comprehensive Database Performance Health Check. The question was how to Convert Date Time AT TIME ZONE. Let us discuss it in today’s blog post.

AT TIME ZONE

Let us assume that you have a business where you have to display the start time of your store multiple timezones. Now if you go by the definition of the relational database and normalization you should not store multiple entries for a single time. It is better that you use the new keyword AT TIME Zone.

Let us first declare a value and store a UTC time in it. Right after that we will display that with different timezone offsets.

DECLARE @dt DATETIME2 = '2021-02-22T01:00:00'
SELECT @dt AT TIME ZONE 'Central European Standard Time' AS CEST,
@dt AT TIME ZONE 'Tokyo Standard Time' AS TST,
@dt AT TIME ZONE 'Eastern Standard Time' AS EST;

SQL Server date and time zone display.

There are many different timezones available out there which this function support and you can check all of them with the help of the following command.

SELECT * FROM sys.time_zone_info
GO

TIME ZONE

Well, that’s it for today.

Here are my few recent videos and I would like to know what is your feedback about them. You can subscribe to my youtube channel here.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.

SQL DateTime, SQL Function, SQL Scripts, SQL Server
Previous Post
Multiple Backup Copies Stripped – SQL in Sixty Seconds #156
Next Post
SQL SERVER – Fix: There is already an object named ‘MyFirstTable’ in the database

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.