Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Epoch to DateTime SQL Server

Tags:

c#

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?

like image 638
thatguy Avatar asked Sep 23 '26 02:09

thatguy


1 Answers

Your timestamp is in milliseconds. 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

like image 113
Micke Avatar answered Sep 24 '26 15:09

Micke