Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

converting db2 datestamp to Unix timestamp

How can i convert 2012-04-12 00:00:00 to a unix timestamp in DB2. is there any inbuild function available in sql s

Thank you.

like image 320
iims Avatar asked Feb 20 '23 14:02

iims


1 Answers

Using the DAYS and MIDNIGHT_SECONDS is much more precise than TIMESTAMPDIFF:

SELECT
86400*(DAYS(CURRENT TIMESTAMP - CURRENT TIMEZONE)-DAYS('1970-01-01'))
+ MIDNIGHT_SECONDS(CURRENT TIMESTAMP - CURRENT TIMEZONE)
"UNIX_TIMESTAMP"
FROM SYSIBM.SYSDUMMY1
like image 59
Stavr00 Avatar answered Mar 05 '23 15:03

Stavr00