How to change the timezone in Azure SQL Database?

2019-02-19 01:07发布

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().

1条回答
在下西门庆
2楼-- · 2019-02-19 01:44

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  
查看更多
登录 后发表回答