GETUTCDATE() and Time Zone (SQL Server)

前端 未结 4 1982
小鲜肉
小鲜肉 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:31

    You can try to use switchoffset like this:

    select switchoffset(CAST(myDate as datetimeoffset),'+05:30')  from someTable
    

    Instead of '+05:30' you can specify your timezone value.

    If you want to use the timezone with GETUTCDATE() then simply add it like this

    select cast(GETUTCDATE() as varchar(20)) + '+5:30'
    

    and if you want to keep it as date only then

    select  switchoffset(CAST(GETUTCDATE() as datetimeoffset),'+05:30')
    

提交回复
热议问题