GETUTCDATE() and Time Zone (SQL Server)

前端 未结 4 1984
小鲜肉
小鲜肉 2020-12-22 03:30

I want to add my time zone with the function GETUTCDATE() in SQL Server. I searched several times, but did not found any relevant solution. Thanks in advance.

4条回答
  •  轮回少年
    2020-12-22 04:20

    From SQL Server 2016 forward (and Azure SQL DB), you can do this:

    SELECT SYSDATETIMEOFFSET() AT TIME ZONE @tz
    

    where @tz is a valid Windows time zone identifier, such as 'Pacific Standard Time', 'Central European Standard Time', etc.

    However, if you are on an older version of SQL Server, or prefer to use IANA time zone identifiers, you can use my SQL Server Time Zone Support project to do the following:

    SELECT Tzdb.UtcToLocal(GETUTCDATE(), @tz)
    

    where @tz is an IANA standard time zone name, such as 'America/Los_Angeles' or 'Europe/Budapest'.

提交回复
热议问题