Reputation: 313
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.
Upvotes: 4
Views: 6492
Reputation: 3314
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
Upvotes: 5
Reputation: 13056
By Unix timestamp
I assume you mean the number of seconds (or whatever) since 1970-01-01 00:00:00 UTC.
There is no built in functionality for this in DB2 (as of V6R1).
You're also up against the following issues:
CURRENT_TIMESTAMP
writes are based on what time the requesting system thinks it is, not the host.TIMESTAMPDIFF
function returns an estimate, not an exact value. You could probably survive for the years/months durations, over sufficient differences, but days aren't likely to cut it.Your best bet will be to start using DAYS
(which returns the number of days since 0001-01-01). Keep in mind you better do everything in UTC, because it will not take DST into account.
Upvotes: 3