I wrote this function a while ago:
Code:
CREATE FUNCTION EPOCH (DB2TIME TIMESTAMP)
RETURNS INTEGER
LANGUAGE SQL
CONTAINS SQL
DETERMINISTIC
RETURN CAST (DAYS(DB2TIME) - DAYS('1970-01-01') AS INTEGER) * 86400 + MIDNIGHT_SECONDS(DB2TIME);
Apparently the timestampdiff function is a bit buggy, as the following would seem to bare out:
values(timestampdiff(2, char(current timestamp - timestamp('1970-01-01-00.00.00'))), epoch(current timestamp))
1 2
----------- -----------
1089106733 1089970733
1 record(s) selected.
One of the above has got to be wrong!