How to calculate the local datetime from a utc datetime in tsql (sql 2005)?

前端 未结 10 1449
Happy的楠姐
Happy的楠姐 2021-02-02 14:13

i want to loop over a period of time in tsql, and print the utc datetimes and our local variant. We live in UTC +1, so i could easily add 1 hour, but in the summertime we live i

10条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-02 15:13

    While the question's title mentions SQL Server 2005, the question is tagged with SQL Server in general. For SQL Server 2016 and later, you can use:

    SELECT yourUtcDateTime AT TIME ZONE 'Mountain Standard Time'
    

    A list of time zones is available with SELECT * FROM sys.time_zone_info

提交回复
热议问题