How to convert Epoch time to date?

In Microsoft SQL Server, the previous answers did not work for me. But the following does work.

SELECT created_time AS created_time_raw, 
dateadd( second, created_time, CAST( '1970-01-01' as datetime ) ) AS created_time_dt 
FROM person

person is a database table, and created_time is an integer field whose value is a number of seconds since epoch.

There may be other ways to do the datetime arithmetic. But this is the first thing that worked. I do not know if it is MSSQL specific.


Please try

select from_unixtime(floor(EPOCH_TIMESTAMP/1000)) from table;

This will give the result like E.g: 2018-03-22 07:10:45 PFB refence from MYSQL


That is EPOCH time: number of seconds since Epoch(1970-01-01). Use this:

SELECT CAST(DATE '1970-01-01' + ( 1 / 24 / 60 / 60 ) * '1310112003' AS TIMESTAMP) FROM DUAL;

Result:

08-JUL-11 08.00.03.000000000 AM