Convert UTC Milliseconds to DATETIME in SQL server

前端 未结 6 1008
没有蜡笔的小新
没有蜡笔的小新 2020-12-02 18:56

I want to convert UTC milliseconds to DateTime in SQL server.

This can easily be done in C# by following code:

DateTime startDate = new DateTime(1970         


        
6条回答
  •  Happy的楠姐
    2020-12-02 19:16

    Using SQL Server 2008R2 this produced the required result:

    CAST(SWITCHOFFSET(CAST(dateadd(s, convert(bigint, [t_stamp]) / 1000, convert(datetime, '1-1-1970 00:00:00')) AS DATETIMEOFFSET), DATENAME (TZoffset, SYSDATETIMEOFFSET())) AS DATETIME)
    

提交回复
热议问题