3

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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
thatguy
  • 99
  • 1
  • 11
  • 1
    What are your typical values in [unixtime]? Are you sure they are seconds and not milliseconds, i.e. x1000? – Micke Aug 28 '15 at 09:28

1 Answers1

2

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

Micke
  • 2,251
  • 5
  • 33
  • 48