Subject | How to convert TIMESTAMP to unix timestamp (number of seconds since epoch) |
---|---|
Author | Mikhail Starovoytov |
Post date | 2009-06-08T18:36:54Z |
I need to convert a timestamp to a unix timestamp in a procedure. I don't seem to find a good way to that. Is there a UDF library that can do this for me.
The best I could come up with is something like this:
select CAST( (CURRENT_TIMESTAMP - CAST('1970-01-01 00:00:00' AS TIMESTAMP)) * 86400 AS INTEGER )+(7*3600) from rdb$database
as you can see I have to correct for my timezone and daylight savings time, so this method will not always work automatically. I'd like a more general, robust method of doing this, sort of like MySQL UNIX_TIMESTAMP().
Is there anything that can help me here
The best I could come up with is something like this:
select CAST( (CURRENT_TIMESTAMP - CAST('1970-01-01 00:00:00' AS TIMESTAMP)) * 86400 AS INTEGER )+(7*3600) from rdb$database
as you can see I have to correct for my timezone and daylight savings time, so this method will not always work automatically. I'd like a more general, robust method of doing this, sort of like MySQL UNIX_TIMESTAMP().
Is there anything that can help me here