将db2 datestamp转换为Unix时间戳 [英] converting db2 datestamp to Unix timestamp
问题描述
如何将2012-04-12 00:00:00转换为DB2中的unix时间戳。是否有任何内置函数可用于sql s
谢谢。
p>由 Unix时间戳
我假设你是指自1970-01-01 00:00:00 UTC以来的秒数(或任何值)。
在DB2中没有内置的功能(从V6R1开始)。
您还可以解决以下问题: p>
- DB2中的所有时间戳记都是本地时间 - 它们不包含时区信息,而所有
CURRENT_TIMESTAMP
写入是基于请求系统认为的时间,不主机。 - 夏令时间频繁更改。
-
TIMESTAMPDIFF
函数返回一个估计 ,不确切的值。你可能会在几年/几个月的时间内生存下来,但是日子不太可能会减少。 - 时间戳算法是不精确的(除其他事项外,假定为几个月总是30天的长度...)
你最好的打赌是开始使用 DAYS
(返回自0001-01-01以来的天数)。请记住,您最好在UTC中执行所有操作,因为它将不考虑DST。
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.
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:
- All timestamps in DB2 are 'local time' - they contain no timezone information, and all
CURRENT_TIMESTAMP
writes are based on what time the requesting system thinks it is, not the host. - Daylight savings time changes frequently. You would need to add overhead to manage this for your conversion.
- The
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. - Timestamp arithmetic is imprecise (among other things, months are assumed to be always 30 days in length...)
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.
这篇关于将db2 datestamp转换为Unix时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!