create or replace function epoch (in db2ts timestamp) returns bigint language sql deterministic no external action return (days(db2ts - current timezone) - days('1970-01-01-00.00.00.000000')) * 86400 + midnight_seconds(db2ts - current timezone);