Mysql date problem in different timezones

java, mysql, timezone

Solution

The date is probably stored as `DATETIME` or `TIMESTAMP`, `2009-08-12 00:00:00 +0530`

Being converted into `GMT+1`, it gives you `2009-08-11 19:30:00 +0100`

`MySQL`'s `DATETIME` doesn't store timezone along with the timestamp, so if your type is `DATETIME`, it's probably your database access layer that converts the dates.

`MySQL`'s `TIMESTAMP` type does store the times in `UTC` and they are converted back into the client's timezone when queried.

Problem

I have been facing this date issue since a long time. Have tried a lot of things but in vain. The problem goes like this: The date entered by the user is '2009-08-12'. It gets stored properly in the db. In the GMT+530 timezone the date gets displayed correctly as well. But when I change the timezone to GMT+1 the date gets displayed as '2009-08-11' i.e it displays the date as 1 day back. Any help or inputs or suggestions would tremendously help. Thanks Nait

Original source