简体   繁体   中英

How to convert Unix time in microseconds with SQL Server?

I've seen a lot on converting Unix time from other formats to datetime, but nothing really from microseconds. How can you SELECT a field this with a timestamp of 1470562081943371 without getting overflows with an output of YYYY-MM-DD HH:MM:SS:MM?

Not sure if this is unit is correct, but...

Declare @UnixTime bigint = 1470562081943371
Select DateAdd(MS,round(((@UnixTime/1000000.)-(@UnixTime/1000000))*1000,0),DateAdd(SECOND,(@UnixTime/1000000),'1970-01-01 00:00:00'))

Returns

2016-08-07 09:28:01.943

Confirmed results with http://www.epochconverter.com/

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM