Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert Epoch time to date?

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.

like image 267
pradeep kumar Avatar asked Apr 25 '14 09:04

pradeep kumar


People also ask

How do I convert epoch time to date in Excel?

If you need milliseconds, you need to add a further multiplication / division by 1000. For example, converting from epoch time (milliseconds) to a date would be "=((((A1/1000)/60)/60)/24)+DATE(1970,1,1)".

How do I convert epoch time to date in Google Sheets?

First, convert that 10 digit Unix Time in seconds to a DateTime. You can do that by dividing Unix Time by 86400. Then add Epoch Date Time and GMT to this DateTime. Again reminding you, if your timezone is GMT- , please do change the last part of the formula accordingly like -time(hr,min,sec) .

How is epoch time calculated?

The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z).


3 Answers

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.

like image 98
Mike Finch Avatar answered Oct 24 '22 06:10

Mike Finch


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
like image 24
MinhD Avatar answered Oct 24 '22 07:10

MinhD


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

like image 38
rahulnikhare Avatar answered Oct 24 '22 08:10

rahulnikhare