Changing the MySQL TimezoneWednesday 11 Apr 2007 17:52 Changing the MySQL Timezone Find the MySQL config file 'my.cnf', add the following section (if not already present) and set your timezone.
[mysqld_safe] timezone = Europe/London I'm a big fan of retrieving DATETIME fields from MySQL databases using the UNIX_TIMESTAMP function. This returns dates in a format I can do stuff with easily using PHP's Date/Time functions.
A UNIX_TIMESTAMP is seconds since 1 Jan 1970 00:00 GMT (or UTC which is the same). This handy format can be used with PHP functions such as date(). Plus, as a number its easy to add or subtract times by simply adding the number of seconds. $d = $row->my_date; // unix timestamp datetime from database
$d += 60*60*24; // add 1 day (60 secs * 60 mins * 24 hours)
echo date("Y-m-d H:i", $date); // print the date in format YYYY-MM-DD HH:MM
But you can encounter problems when using functions such as date with values you've retrieved from your MySQL tables as these functions convert to the current MySQL timezone. In my case this problem came to light when a server patch somehow altered this setting and the dates on my blog went 5 hours out. This was made even worse by the fact that I feed those dates back into queries on my database. The answer, as dude and myself found out is to set the MySQL timezone. Comments (1) 7 Mar 2008 07:34 by hair balls really hairy | Show channel: 11 Apr 2007 Changing the MySQL Timezone 10 Apr 2007 UPS picks up my Xbox 360 09 Apr 2007 Levi Roots Reggae Reggae Sauce 07 Apr 2007 Whatever happened to Widescreen TV? 06 Apr 2007 Xbox 360 crash 05 Apr 2007 Sky Satellite Movie Channels 02 Apr 2007 Cobra Beer 29 Mar 2007 Digital photos make great textures 28 Mar 2007 Blog tag code written 25 Mar 2007 First blog entry |