Determine Time Zone Offset in T-SQL

后端 未结 3 924
予麋鹿
予麋鹿 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:50

    Hmm, I guess I'm not understanding the problem. If the database app is already storing UTC timestamps for all of it's transactions, and you want to sum up some values since the first of the year "local time", your condition would have to be something like:

    (timestamp + (getutcdate() - getdate())) > cast('01/01/2008' as datetime)
    

    The DST can be on or off depending on when in the year the query is run - but getdate() takes it into account, so you have to dynamically calculate the offset every time.

提交回复
热议问题