none
SQL function to convert UTC datetime to a specific zone datetime RRS feed

  • Question

  • Hi, 

    Is there a SQL function to convert the UTC datetime to EST or specific time zone   ?  

    Also, how to consider the day light savings - time changes  ?

    Wednesday, January 22, 2020 9:59 PM

Answers

All replies

  • SELECT convert(datetime2(0), '2020-01-20 00:00') AT TIME ZONE 'Eastern Standard Time',
           convert(datetime2(0), '2020-06-20 00:00') AT TIME ZONE 'Eastern Standard Time'

    These gives you values with the type datetimeoffset. As you can see, daylight savings is handled, but I would assume only according the current rules.

    If you want this to be a pure datetime2 value, you would have to cast to string which is short enough to remove the time-zone offset.

    A list of time zone is found in sys.time_zone_info. The data here is take from the Windows registry.


    Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

    Wednesday, January 22, 2020 10:53 PM
  • Hi guest369,

    Thank you for your issue. 


    Did you mean that use CONVERT  and AT TIME ZONE ?Please understand AT TIME ZONE  firstly. 

    Also , please check AT TIME ZONE: The easy way to deal with time zones and daylight savings time .

    Best Regards,

    Rachel 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by guest369 Thursday, January 23, 2020 9:04 PM
    Thursday, January 23, 2020 2:23 AM
  • Thanks!
    Thursday, January 23, 2020 9:04 PM