Epoch Date Conversion to SQL Server

2019-09-07 11:32发布

问题:

Good Day,

I have a question. What type of epoch date's are these and how would I convert them into a SQL Server datetime format.

37564691530
37564704499
37564708633
37564721033
37564743361
37564746236

I have googled for 2 days and cant find anything except this formula which gives me an arithmetic overflow message when i try to convert it.

select 
    DATEADD(ss, 37564691530 - 3600 * 5, CONVERT(DATETIME, '1900-01-01 00:00:00', 102)) 

Any help would really be appreciated.

回答1:

13 digit epoch represent total milliseconds 10 digit epoch represent total seconds. You have first one - milliseconds. And sql DateAdd function accept second parameter(Increment) as Integer. You try to pass a bigint value. Thats why throw Arithmetic overflow error.

try this

DECLARE @MS BIGINT
SET @MS = 37564746236
select DATEADD(SECOND, @MS / 1000, '1970-01-01')