Is there a PHP equivalent of `date_default_timezone_set ()` that works in MySQL?
This works fine in PHP
date_default_timezone_set('my/timezone');
$actualDate = date('Y-m-d');
Now when you make requests, I like to do
INSERT INTO articles (title, insert_date) VALUES ('My Title', now())
The problem with this: now()
in MySQL it is different from what it would be if it was calculated in PHP (and therefore against the set timezone).
Is there a way, say an SQL query, to set the default timezone for MySQL?
thanks
a source to share
http://dev.mysql.com/doc/refman/5.1/en/time-zone-support.html
If you have the SUPER privilege, you can set the value of the global clock server at runtime using this statement:
mysql> SET GLOBAL time_zone = timezone;
Time zone per connection. Each client that connects has its own time zone, specified by the session_zone variable. Initially, the session variable takes its value from the global time_zone variable, but the client can change their own timezone using this statement:
mysql> SET time_zone = timezone;
a source to share
Something you might try is to store all your dates / times in UTC. So you would use
date_default_timezone_set('UTC');
$actualDate = date('Y-m-d');
and
INSERT INTO articles (title, insert_date) VALUES ('My Title', UTC_TIMESTAMP())
Then you have to convert UTC date / time to user's timezone before displaying it.
a source to share