Saturday, March 26, 2011

TIME ZONE CONVERSION in DB2 UDB

There was requirement, an attribute of type DATETIME is stored in the GMT format and it needs to be converted into CST format while presenting the data to end users in reporting tool(BO). In additional, we require to handle the DST(Day Light Savings) since the servers are present in U.S.
So, we know that during DST, the CST time would be equal to GMT- 5 hrs else GMT-6 hrs. The challenge was in figuring out the when the DST starts and ends every year.There were no built in functions available handling this scenario. After a quite good effort, i found function called TIMEZONE in DB2, which gives the difference between GMT and the time zone of the application server(The application servers installed at different locations around the world follow their specific timezone).So when i queried in my database, it returned - 6 hours, which is difference between CST & GMT.Still, i had a query how would the TIMEZONE variable adjusts during DST.
The trick is these databases were installed on AIX (OS) and the TIMEZONE variable gets the value from these servers.
So happily I used
DATE ATTRIBUTE + TIMEZONE = DATE (in CST FORMAT).

Hope this might help you guys in future.

- Upendra

No comments:

Post a Comment