Question

Hi I have a column with number datatype the data like 1310112000 this is a date, but I don't know how to make it in an understandable format: ex: 10-mar-2013 12:00:00 pm

Can any one please help me.

Was it helpful?

Solution 2

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

OTHER TIPS

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top