Reputation: 2959
I need to dynamically change the timezone for mysql sessions due to traversing multiple databases which have different time zones.
How do I setup mysql to be tiemzone based for all mysql date related queries?
Upvotes: 4
Views: 4278
Reputation: 65527
You can use SET TIME_ZONE
to set your session to a specific UTC offset.
For example, I'm in UTC -05:00, but I can change to UTC like this:
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2011-03-02 12:32:39 |
+---------------------+
1 row in set (0.00 sec)
mysql> set time_zone = '+00:00';
Query OK, 0 rows affected (0.00 sec)
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2011-03-02 17:32:45 |
+---------------------+
1 row in set (0.00 sec)
Upvotes: 7