How can I convert a Sql Server 2008 DateTimeOffset to a DateTime

后端 未结 6 1401
独厮守ぢ
独厮守ぢ 2020-11-27 05:15

I\'m hoping to convert a table which has a DATETIMEOFFSET field, down to a DATETIME field BUT recalculates the time by taking notice of the offset.

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-27 06:13

    DateTimeoffset (Timezone) conversion in SQL Server.

    SQL Server 2016 (13.x) and later

    Exmample

    Select GETUTCDATE()
    Select Convert(DATETIME, GETUTCDATE() AT TIME ZONE 'UTC' AT TIME ZONE 'Central European Standard Time')
    Select Convert(DATETIME, GETUTCDATE() AT TIME ZONE 'UTC' AT TIME ZONE 'India Standard Time')
    

    Result will be

    2020-08-18 08:22:21.640
    2020-08-18 10:22:21.640
    2020-08-18 13:52:21.640
    

提交回复
热议问题