converting db2 datestamp to Unix timestamp

db2, unix-timestamp

Solution

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

Problem

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.

Original source