0

I have a column called start time which is populated with a number like "1465815600000" and increasing. This column is the number of milliseconds from the year 1970 jan 1st 12.00:00:000 AM to a certain date in june 2016. This is in integer, which I need to convert it to date time format.

EX: 1465815600000 => 2016-06-12-12:00:00 (something like this)

Can somebody help me with to write this function?

user1960217
  • 131
  • 2
  • 3
  • 15

1 Answers1

3

Try this:

TSQL:

SELECT DATEADD(SECOND,1465815600,'1970-1-1')

MYSQL:

SELECT DATE_ADD('1970-1-1',INTERVAL 1465815600 SECOND)

Why SECOND? because given 1465815600000 is greater than the max integer value and that would cause the arithmetic overflow exception, so in order to prevent it, we divide it by 1000 and use SECOND instead of MILISECOND

Vahid Farahmandian
  • 6,081
  • 7
  • 42
  • 62