I have a weird problem concerning mysql timezone.
In my website config file i have this line which sets the timezone :
mysql_query("SET SESSION time_zone = '$offset';"); // Offset is properly calculated, no worries about that
The funny part is that if i add another line right after this like this :
$q = mysql_query("SELECT NOW() as now");
$row = mysql_fetch_array($row);
echo $row["now"];
After executing that code, the time is displayed correctly.
BUT, in some other queries i insert rows in tables that have a column named date that defaults to CURRENT_TIMESTAMP.
Rows are inserted like this:
INSERT INTO `sessions` (`user_id`) VALUES `1`
(The sessions table has a date
column that defaults to CURRENT_TIMESTAMP)
But the value inserted in DB still points back to the timezone of the server :((
Any ideas how to work through this ?
You have to understand that MySQL maintains multiple time zone settings:
See http://dev.mysql.com/doc/refman/5.5/en/time-zone-support.html for details.
Date/time values are stored in two different ways:
From the above it should become clear that the values that you see when you read from unix timestamp based columns are not necessarily what is really stored in the DB. They are converted using the server time zone and the client time zone. The result can be confusing if you do not understand the details of the mechanics.
For a first test try to find out the current settings in each of your client programs by executing
SELECT @@global.time_zone, @@session.time_zone;
The global time zone will always be the same. But the session time zone can differ from client application to client application and will change the results of your read and write operations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With