cancel
Showing results for 
Search instead for 
Did you mean: 

How can I convert an Epoch datetime to a timestamp?

Former Member
0 Kudos
64,770

How can I convert an Epoch timestamp to a timestamp using SQL Anywhere?

For example: Input Epoch timestamp: 1354320000

Desired output Timestamp: 2012-12-01 00:00:00

Human time (GMT): Sat, 01 Dec 2012 00:00:00 GMT

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Mark your answer has the extra ".000000"

I think this is what I need to do, right?

--CONVERT FROM EPOCH TO DATETIME:

SELECT DATEFORMAT(dateadd(SS,CONVERT(INT, 1354320000), CAST('1970-01-01 00:00:00' as datetime) ), 'yyyy-mm-dd hh:mm:ss') as myDateTime;

---CONVERT FROM DATETIME TO EPOCH GMT+0:

SELECT CAST(datediff(ss, 'Jan 01 1970', '2012-12-01 00:00:00' ) AS CHAR) as myEpochDate;

MarkCulp
Participant
0 Kudos

EPOC time is the number of seconds since 1970 Jan 1.... so use:

select dateadd( SECOND, 1354320000, '1970-1-1' )