0

I'm trying to insert or update entries in a table, to Athens timezone. I'm using a shared hosting so I can't set global server timezone.

When I run this multiple query:

SET time_zone="Europe/Athens";
SELECT NOW();

I get the desired Athens time, but when I run something like:

SET time_zone="Europe/Athens";
UPDATE `db`.`tbl` SET `the_time` = NOW() , `foo` = '1' WHERE `tbl`.`id` = 100;

the time set the updated entry is still the server's time! Why is this happening and how can I fix this?

efrat
  • 11
  • 1
  • 1
  • 2

1 Answers1

1

MySQL converts TIMESTAMP values from the current time zone to UTC for storage, and back from UTC to the current time zone for retrieval. (This does not occur for other types such as DATETIME.) By default, the current time zone for each connection is the server's time. The time zone can be set on a per-connection basis. As long as the time zone setting remains constant, you get back the same value you store. If you store a TIMESTAMP value, and then change the time zone and retrieve the value, the retrieved value is different from the value you stored. This occurs because the same time zone was not used for conversion in both directions. The current time zone is available as the value of the time_zone system variable.

http://dev.mysql.com/doc/refman/5.6/en/datetime.html

zod
  • 12,092
  • 24
  • 70
  • 106