Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting Unix epoch time to extended ISO8601

I have 3 tables I would like to work on using the date, however one of the tables includes the date in unix epoch format. Here is an example of the 3 fields:

Table1: 2017-02-01T07:58:40.756031Z
Table2: 2017-02-07T10:16:46Z
Table3: 1489236559

I would like to convert the date in table 3 to match the format of table 2 as closely as possible. This is what I have right now:

SELECT cast(from_unixtime(tstart) as timestamp) as ISODATE from scada_logs

This gives me something tantalizingly close, but not quite there. Here is what I get:

ISODATE
2017-03-20 14:31:06.000
2017-03-20 14:31:06.000

I've played around with this for a couple of hours but I'm not getting any closer. Does anyone have any ideas?

Thank you!

like image 365
Kelly Norton Avatar asked Mar 21 '17 12:03

Kelly Norton


People also ask

How do I convert epoch time to real time?

Convert from epoch to human-readable datemyString := DateTimeToStr(UnixToDateTime(Epoch)); Where Epoch is a signed integer. Replace 1526357743 with epoch. =(A1 / 86400) + 25569 Format the result cell for date/time, the result will be in GMT time (A1 is the cell with the epoch number).

What are the differences between ISO 8601 and Unix epoch time formats?

How is it more accurate? ISO-8601 allows for leap seconds, it uses the same second counting frequency as the Unix timestamp, it can represent dates before 1970 and after 2038 (64-bit Unix timestamps will also.) and it's an international standard.

How do I convert Unix epoch time to datetime in Excel?

If you have a list of timestamp needed to convert to date, you can do as below steps: 1. In a blank cell next to your timestamp list and type this formula =(((A1/60)/60)/24)+DATE(1970,1,1), press Enter key, then drag the auto fill handle to a range you need.


1 Answers

Option 1: date_format

presto> select date_format(from_unixtime(1489236559),'%Y-%m-%dT%H:%i:%sZ');
        _col0
----------------------
 2017-03-11T12:49:19Z

Option 2: to_iso8601

presto> select to_iso8601(from_unixtime(1489236559));
          _col0
--------------------------
 2017-03-11T12:49:19.000Z
like image 198
David דודו Markovitz Avatar answered Oct 21 '22 18:10

David דודו Markovitz