Convert db2 datestamp to Unix timestamp

How can I convert 2012-04-12 00:00:00 to a unix timestamp in DB2. is there a built-in function available in sqls

Thank.

+3
source share
2 answers

By Unix timestampI assume that you mean the number of seconds (or something else) from 1970-01-01 00:00:00 UTC.

DB2 has no built-in functions (with V6R1).
You are also not against the following problems:

  • All timestamps in DB2 are “local time” - they do not contain time zone information, and all entries CURRENT_TIMESTAMPare based on when the requesting system thinks it is not a host.
  • . .
  • TIMESTAMPDIFF , . , /, , .
  • ( , 30 ).

DAYS ( 0001-01-01). , UTC, DST.

+3

DAYS MIDNIGHT_SECONDS , TIMESTAMPDIFF:

SELECT
86400*(DAYS(CURRENT TIMESTAMP - CURRENT TIMEZONE)-DAYS('1970-01-01'))
+ MIDNIGHT_SECONDS(CURRENT TIMESTAMP - CURRENT TIMEZONE)
"UNIX_TIMESTAMP"
FROM SYSIBM.SYSDUMMY1
+2

All Articles