How to set the server time/timezone

Article Details
Article ID: 138
Created On: 13 Jul 2007 07:06 AM


All our servers' time/timezone are set to GMT/UTC.

You can customise your time/timezone through your scripts.

To change the time zone in php:

Method 1:

you can insert this code into .htaccess:

php_value date.timezone 'Australia/Melbourne'

Method 2:

Inside your PHP code:

For more information see:

To change the time zone in MySQL

Depending on how your database gets its time, this may be all you need. However, if the date/time data is generated in your sql database queries, for example "update tablename set order_date=now()", then you need to change the timezone within mysql itself. 

The ideal situation is to store all date/time in GMT/UTC time zone and only convert it when you want to display the date/time, by adjusting it to the time zone that matches your user's timezone. This is a complex issue and needs to be done correctly. For example, if you want to store the date/time in GMT, do not set the time_zone variable in mysql. You will need to perform the timezone conversion perhaps within your php code that displays the date/time value. 

If you don't care about timezone portability and all you want is that everything should be stored / processed / displayed in say Queensland time, then set the TZ variable in php and also set the time_zone variable in Mysql and you're done.

This article explains the timezone handling in mysql:

So as soon as you've connected to mysql, simply execute "set time_zone = '+10:00'" query.  for example, to adjust your date/time values to GMT+10 (Queensland time zone). This needs to be done each time you connect to the database.