sql server convert datetime into another timezone?

后端 未结 3 854
日久生厌
日久生厌 2020-12-10 21:58

How do I convert the current time (datetime) in my timezone into another timezone, say France ? I looked around in SO, but did not find any posts which could help me. I am u

相关标签:
3条回答
  • 2020-12-10 22:19
     select CONVERT(datetime,SWITCHOFFSET(CONVERT(datetimeoffset,GetUTCDate()),'+05:30')) Date_India,
    
     select CONVERT(datetime,SWITCHOFFSET(CONVERT(datetimeoffset,GetUTCDate()),'+03:30')) Date_Iran
    

    check here

    0 讨论(0)
  • 2020-12-10 22:30

    I also agree the correct SQL Query is using GetUTCDate() as you see in the screenshot.

    select CONVERT(datetime,SWITCHOFFSET(CONVERT(datetimeoffset,GetUTCDate()),'+05:30')) Date_India_withUtcDate
    

    0 讨论(0)
  • 2020-12-10 22:36

    Please replace getdate() with GetUTCDate() to get accurate result otherwise the offset (5:30) in this case will be added to the current time (which will already have some offset) and will result in incorrect result.

    For instance if you are in Pakistan then GetDate() will give you time as GMT+5:00 and adding 5:50 offset in this time will result in GMT + 10:30 which is totally wrong.

    0 讨论(0)
提交回复
热议问题