Please be aware that the content in SAP SQL Anywhere Forum will be migrated to the SAP Community in June and this forum will be retired.

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

asked 07 Dec '12, 13:53

sybasetester's gravatar image

sybasetester
513310
accept rate: 0%


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

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

answered 07 Dec '12, 15:01

Mark%20Culp's gravatar image

Mark Culp
24.9k10141297
accept rate: 41%

edited 07 Dec '12, 15:02

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;

permanent link

answered 07 Dec '12, 15:36

sybasetester's gravatar image

sybasetester
513310
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×68
×25
×22

question asked: 07 Dec '12, 13:53

question was seen: 62,701 times

last updated: 07 Dec '12, 15:36