Our iSeries (aka AS400, aka i5, aka SystemI) runs in local time, but we have an application, that uses UTC (written in Java, connected by JDBC to the iSeries DB).
How can I generate UTC-timestamps via SQL on that system?
DB2/400 (which likes to be different in details from other DB2 flavours), has a special register called CURRENT TIMEZONE
. It contains a numeric value, that can be subtracted from a timestamp or time value.
In an example query:
SELECT
CURRENT TIMESTAMP AS local,
CURRENT TIMEZONE AS offset,
CURRENT TIMESTAMP - CURRENT TIMEZONE AS utc
FROM SYSIBM.SYSDUMMY1
Gives you something like:
+----------------------------+--------+----------------------------+
| LOCAL | OFFSET | UTC |
+----------------------------+--------+----------------------------+
| 2014-05-27 14:09:19.127339 | 20.000 | 2014-05-27 12:09:19.127339 |
+----------------------------+--------+----------------------------+
Notes:
SYSIBM.SYSDUMMY1
is a special table supplied by IBM, with the sole purpose of having exactly one row with exactly one column.NOW() - CURRENT TIMEZONE
and CURRENT TIME - CURRENT TIMEZONE
work as well.