English 中文(简体)
将db2日stamp改为Unix时stamp
原标题:converting db2 datestamp to Unix timestamp

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

谢谢。

问题回答

采用<代码><MIDNLI_SECONDS更为准确。 TIMESTAMPDIFF:

SELECT
86400*(DAYS(CURRENT TIMESTAMP - CURRENT TIMEZONE)-DAYS( 1970-01-01 ))
+ MIDNIGHT_SECONDS(CURRENT TIMESTAMP - CURRENT TIMEZONE)
"UNIX_TIMESTAMP"
FROM SYSIBM.SYSDUMMY1

缩略语 我假定,自1970-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...)

阁下最好先使用<条码>(接下自0001-01以来的天数)。 牢记你在万国邮联中做得更好,因为它将而不是考虑到国贸总协定。





相关问题
DB2 varchar index join

For DB2... table1.a is varchar(30) and has an index on it. table2.b is varchar(45) and has an index on it. Will table1.a = table2.b use the index on table1, table2, or both? Although it would seem ...

How to put a constraint on two combined fields?

I d like to put a constraint, a check or a foreign key, on two combined fields from table1 to another field in table2. Here is what I tried, but both gave me errors: ALTER TABLE table1 ADD ...

Odd WHERE NOT EXISTS performance on DB2

I am experiencing very odd performance on DB2 version 9.1 when running the query below: select a.CYCL_NUM , a.AC_NUM , a.AUTHS_DTE , a.PL_ID , a.APRVD_RSPN_CDE , a.AUTHS_AMT , a....

AS400 DB2 Journals search

I am new to DB2 administration on AS400, could you point me to the best practices/tools to search for errors in the DB2 journals? So far I use the DSPJRN command but I am unable to make research. ...

2. 循环检测,采用回收分级系数

甲状腺可使用其专有的CONNECT,自v2起就进行分级查询。 在最近发表的第11g号新闻稿中,他们增加了复位的分级系数,也称为休养。

Tossing out certain result rows in a left join

In DB2, using the following left join select a.deptno, a.deptname, b.empno from #dept a left join #emp b on a.deptno = b.workdept on two tables, gets me a list like: dpt name emp ----------...