Knowledgebase & Downloads
The knowledgebase provides documentation written by our team. Please select a category or search for answers.
Articles
MySQL timezone
System timezone is fixed for shared server. It must be so
because we cannot match each an every client preference when the paramter can only have single value.
Client can still use different timezones but in their sessions.
Consult per-connection time zone section in
http://dev.mysql.com/doc/refman/5.5/en/time-zone-support.html
Example (when you are connecting with a client on the same machine and thus the same timezone as server)
mysql> select timediff(now(),convert_tz(now(),@@session.time_zone,'+00:00'));
+----------------------------------------------------------------+
| timediff(now(),convert_tz(now(),@@session.time_zone,'+00:00')) |
+----------------------------------------------------------------+
| -06:00:00 |
+----------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> SELECT TIMEDIFF(NOW(), UTC_TIMESTAMP);
+--------------------------------+
| TIMEDIFF(NOW(), UTC_TIMESTAMP) |
+--------------------------------+
| -06:00:00 |
+--------------------------------+
1 row in set (0.00 sec)
mysql> SET time_zone = '+3:00';
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT TIMEDIFF(NOW(), UTC_TIMESTAMP);
+--------------------------------+
| TIMEDIFF(NOW(), UTC_TIMESTAMP) |
+--------------------------------+
| 03:00:00 |
+--------------------------------+
1 row in set (0.00 sec)
mysql> SELECT @@global.time_zone, @@session.time_zone;
+--------------------+---------------------+
| @@global.time_zone | @@session.time_zone |
+--------------------+---------------------+
| SYSTEM | +03:00 |
+--------------------+---------------------+
1 row in set (0.14 sec)
Do I need to worry?
If your client is in India and he saves his local time say 10:30 PM (IST) then
it will be saved as 11:00 AM server time (CST).
Server time is GMT-6, IST is GMT+5:30 so it gives 11:30 hours of difference (10:30 PM - 11:10 = 11 AM).
Anytime later when your client connects from India and run SELECT query, he will get 10:30PM
as the time will be converted to his timezone.
This is assuming his client software explicitly or implicitly sets session timezone to IST (GMT+5:30).
Note that custom timezones can also be set for PHP, shell and JVM (Java).
See also http://www.jvmhost.com/articles/java-and-timezones
For php you can set it in ~/.user.ini with for example:
date.timezone = America/New_York
For bash you can set it in .bashrc with for example:
export TZ="/usr/share/zoneinfo/Asia/Calcutta"
- © 2016-2024 JVMHost.com All rights are reserved.