mySQL TIME function and Timezone
I want to use the NOW()
function with a specific timezone, say GMT+8 for a user and GMT-2 for another user. How can I achieve this?
I am guessing that the time for NOW()
is related somewhat to the timezone and time of the SQL server, but I want it to be such that FN(GMT+8) always give me the NOW()
in GMT+8 irregardless of the timezone the SQL server is in.
Mini question: How do i display/know the current time 开发者_如何学JAVAof the SQL server?
The NOW()
function provides the current time in the local timezone of the server. If you wish to convert to a different timezone, you can use CONVERT_TZ()
UPDATE:
You can use a per-connection timezone (that doesn't affect the system timezone) and get the effect you want:
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2011-06-03 22:40:51 |
+---------------------+
1 row in set (0.00 sec)
mysql> SET time_zone = '+08:00';
Query OK, 0 rows affected (0.00 sec)
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2011-06-04 10:41:15 |
+---------------------+
1 row in set (0.00 sec)
精彩评论