View Full Version : How to change the system time of my site ?
b-707
10-20-2009, 12:12 PM
Hello,
I want my site showing GMT+1.
Where ca I change the time ?
Asking you to reply / thx for your reply
Josef
felgall
10-20-2009, 02:21 PM
You can't change the system time because that would affect hundreds of other sites that probably want the timezone completely different from what you want.
There are two ways you can go.
The first approach is to convert everything to GMT as it comes in and convert everything from GMT as it goes out. That way you can ask your visitors what their timezone is and allow them to enter and see all the times in their own timezone.
The other approach is to specifically change the timezone that your scripts are using. If you want to change the timezone for your PHP scripts then there are two ways to do that. The easiest way is to add an entry to your php.ini file specifying the timezone to use. You can also set it just for specific scripts by setting an evnironment variable at the top of the script.
For example I have one of my sites where I want the timezone to be my local one so I have the following line in my php.ini
date.timezone = "Australia/Sydney"
See http://php.net/manual/en/timezones.php for the complete list of timezones that can be used so as to select the right one for what you need.
Ferdinand
10-20-2009, 04:24 PM
If you use Wordpress, you'll find a plugin for adjusting the timezone.
felgall
10-20-2009, 04:30 PM
If you use Wordpress, you'll find a plugin for adjusting the timezone.
You don't need a plugin for the timezone in WordPress. It displays all times in each user's local timezone for them by default. b-707 is unlikely to be using Wordpress as then there wouldn't have been a need to ask the question in the first place since timezone handling is built into WordPress.
jgauld
01-14-2010, 03:13 PM
PHP and MYSQL are two separate entities, so changing a php.ini setting for timezone will not affect mysql at all.
SETUP
I have a PHP site built in Dreaweaver CS4 which connects to a MYSQL database. In my database, I have a table with two columns, named "lastModifiedDate" and "createdDate" - in that order (this is important).
Both columns have their TYPE set to TIMESTAMP, and I have the "lastModifiedDate" column's ATTRIBUTE set to "ON UPDATE CURRENT_TIMESTAMP". Since "lastModifiedDate" column comes before the "createdDate" column it ensures that the record will update its timestamp every time it is modified, and the "createdDate" will only record the TIMESTAMP when the record is first created.
TIMEZONE PROBLEM
My PHP page uses the NOW() function to set the date when a new record is created. The problem is, is that the server is on Mountain Time and I'm on Eastern Time. So when I return a list of the records, they are always shown as having been created or modified two hours behind their actual time.
Adapting the NOW() function like this only partially works:
SELECT DATE_ADD(NOW(), INTERVAL 2 HOUR);
This will correctly input the "createdDate" value, but every time the record is updated, it will use the current server time, which is 2 hours behind.
What you need to do is change the default MYSQL time_zone setting, and since I don't have GLOBAL access to the MYSQL server, I have to set the default time_zone setting by session.
TIMEZONE FIX
Each client that connects has its own time zone setting, given by the session time_zone variable. Initially, the session variable takes its value from the global time_zone variable, but the client can change its own time zone with this statement:
mysql> SET time_zone = timezone;
And to call this in your PHP page, simply add the following code to the top of your page:
mysql_query("SET time_zone = 'timezone'");
where timezone = your local timezone. In my case for EST, this became:
mysql_query("SET time_zone = 'US/Eastern'");
Problem solved.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.