java java
java java

Reputation: 415

How to convert Local_Timestamp into UTC Timestamp?

The Timestamp is the localtime of the DB2 Server. The date was stored in the time zone Europe / Berlin.

I would like to convert the then stored date to UTC. Is there a way to calculate this in DB2 Dialect?

Upvotes: 2

Views: 3305

Answers (3)

MichaelTiefenbacher
MichaelTiefenbacher

Reputation: 4005

Check out the TO_UTC_TIMESTAMP scalar function

 values TO_UTC_TIMESTAMP(TIMESTAMP'2019-10-01 00:00:00', 'Europe/Berlin')

Please note the second parameter is case sensitive. There is also a FROM_UTC_TIMESTAMP if needed.

Upvotes: 1

data_henrik
data_henrik

Reputation: 17118

Your best bet is to use the TIMEZONE function and to use CURRENT TIMEZONE as help for the input.

The function converts date and time from one to another timezone. The register CURRENT TIMEZONE gives you the difference between server timezone and UTC.

Upvotes: 1

kkuduk
kkuduk

Reputation: 601

As @data_henrik pointed out, CURRENT TIMEZONE is the special register to use, it can be simply subtracted from CURRENT TIMESTAMP e.g.:

db2 "values CURRENT TIMESTAMP - CURRENT TIMEZONE"

1                         
--------------------------
2019-10-16-11.36.24.025651

  1 record(s) selected.

Upvotes: 1

Related Questions