Determine Time Zone Offset in T-SQL

后端 未结 3 964
予麋鹿
予麋鹿 2021-01-06 01:03

My database application is going to be deployed at multiple sites in different time zones.

I need a T-SQL function that will determine the UTC timestamp of midnight

3条回答
  •  忘掉有多难
    2021-01-06 01:45

    Unless I'm mistaken, the GETUTCDATE() function uses the time zone defined on the server - it has no information regarding the client's time zone (or any time zone). I don't think that information is stored anywhere in SQL Server 2005, which makes it impossible for it to calculate this information.

    Maybe you could 'borrow' the data from Oracle's time zone file and build your own SQL Server function?

    Off topic (could be useful to someone else) but if you were using Oracle, you could use the FROM_TZ function and 'AT TIME ZONE':

    FROM_TZ(YOUR_TIMESTAMP, 'UTC') AT TIME ZONE 'America/Dawson_Creek'
    

提交回复
热议问题