Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the timezone in Azure SQL Database?

We would like to get the date in a specific location, either by using something like the C# solution:

TimeZoneInfo.ConvertTimeBySystemTimeZoneId(DateTime.Now, "West US Time");

Or by setting the Azure SQL Database timezone and then using getdate().

like image 899
Guy Assaf Avatar asked Feb 06 '23 16:02

Guy Assaf


1 Answers

From MSDN: Use AT TIME ZONE

SELECT CONVERT(datetime, '03/29/2015 01:01:00')   
AT TIME ZONE 'Central European Standard Time';  
--2015-03-29 01:01:00.000 +01:00  

--Time between 02:00 and 03:00 is converted as +01!  
SELECT CONVERT(datetime, '03/29/2015 02:01:00')   
AT TIME ZONE 'Central European Standard Time';  
--2015-03-29 02:01:00.000 +01:00  

SELECT CONVERT(datetime, '03/29/2015 03:01:00')   
AT TIME ZONE 'Central European Standard Time';  
--2015-03-29 03:01:00.000 +02:00  
like image 157
TheGameiswar Avatar answered Feb 09 '23 21:02

TheGameiswar