简体   繁体   中英

Convert Epoch to DateTime SQL Server

Apologies my cap broke mid title.

I'm having issues with the following:

dateadd(S, [unixtime], '1970-01-01')

to convert epoch to datetime in SQL Server, but received the following error:

Arithmetic overflow error converting expression to data type int.

Obviously it means the epoch is too big for int ? even though this code has worked previously; bizarrely. is there a way to call this with bigint?

eg epoch:

1440753397054

and I believe the limit is 10 digits, so an alternative?

Your timestamp is in milli seconds. Try dividing it by 1000 and I'm sure it will work.

1440753397054 / 1000 = 1440753397,054 corresponds to (assuming GMT):

Fri, 28 Aug 2015 09:16:37 GMT

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