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.
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;
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
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.
- Forwarded Records and Performance – SQL in Sixty Seconds #155
- Hide Code in SSMS – SQL in Sixty Seconds #154
- Zoom in SSMS – SQL in Sixty Seconds #153
- Transfer Schema of Table – SQL in Sixty Seconds #152
- Find a Table in Execution Plan – SQL in Sixty Seconds #151
Reference: Pinal Dave (https://blog.sqlauthority.com)