Support Center » Knowledgebase » General Topics » How to set the server time/timezone

How to set the server time/timezone



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:
<?php
putenv("TZ=Australia/Sydney");
date_default_timezone_se("Australia/Sydney");
?>

For more information see: http://php.net/manual/en/timezones.php

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: http://dev.mysql.com/doc/refman/5.1/en/time-zone-support.html

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.


Article Details
Article ID: 138
Created On: 13 Jul 2007 07:06 AM
 Back
 Login [Lost Password] 
Email:
Password:
Remember Me:
Please note that the login and password to the support area is NOT the same as your hosting control panel login and password
 
 Search
 Article Options
Home | Register | Submit a Ticket | Knowledgebase | Downloads | Control Panel User's Guide | Server Status
Language: