How to convert Epoch time to date?

一曲冷凌霜 提交于 2021-01-27 05:10:08

问题


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.


回答1:


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



回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/23289218/how-to-convert-epoch-time-to-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!