Search code examples
mysqlsqldatabaseh2database-administration

Dateadd function to convert epoch time


I am having preexisting table name 'ABC' in H2 Database.and description is,

FIELD              | TYPE                           | NULL | KEY | DEFAULT
ID                 | DECIMAL(19)                    | NO   |     | NULL
EVENT              | BIGINT                         | YES  |     | NULL

in 'EVENT' column I have some unix timestamps (epoch time in millisec.) data.

ID |   EVENT
1  |  1468318907575 
2  |  1468321000459 

using DATEADD function we can convert unix timestamp into normal date. but the input needed is in seconds (11 Digits).

Is there any way i can write a sql function which takes data from my EVENT column and convert it into DATE format same like below function is doing for values in ABC table (13 digits) bigint value.

select DATEADD('SECOND', 1348560343, DATE '1970-01-01');

please help me in this.

Thanks in advance !!!

Reagrds


Solution

  • select DATEADD('SECOND', SUBSTRING(Event,1,11), DATE '1970-01-01');