Teach
08-04-2008, 08:54 AM
Hi guys. I hope you can help me with these please... I'm completely stumped
We use a timezone selection for locale, and I want to further use that to basically (when someone is logged in) to show all the website dates in their own time. This includes dates stored in our MySQL database.
The timezone selections are at http://pastebin.com/mf714dfa (too large to post here), these are the values that are in our `timezone` field in our `user` table
So, that's fine...
In my functions.php, included by all files I've tried the following:
$search=mysql_fetch_array(mysql_query("SELECT * FROM user WHERE account='".mysql_real_escape_string($_SESSION['account'])."'"));
$timezone=$search['timezone'];
putenv("TZ=$timezone");
mktime(0,0,0,1,1,1970);
and also I tried:
date_default_timezone_set($timezone);
So the problems:
- For some dates, it seems to work fine. But on all our datetimes (stored as yyyy-mm-dd hh:mm:ss) it doesn't change them. They remain in the London timezone where the server is hosted
- Secondly, when inserting stuff into the database, we use:
$dateadded=date('Y-m-d H:i:s');
With the new timezone, it inserts it under their time (which is expected) but we don't want that to happen. All the times in the SQL database should be local to the server, and then output differently...
For the moment I've disabled all this to save it screwing up our database.
Any help is much appreciated. Thank you
We use a timezone selection for locale, and I want to further use that to basically (when someone is logged in) to show all the website dates in their own time. This includes dates stored in our MySQL database.
The timezone selections are at http://pastebin.com/mf714dfa (too large to post here), these are the values that are in our `timezone` field in our `user` table
So, that's fine...
In my functions.php, included by all files I've tried the following:
$search=mysql_fetch_array(mysql_query("SELECT * FROM user WHERE account='".mysql_real_escape_string($_SESSION['account'])."'"));
$timezone=$search['timezone'];
putenv("TZ=$timezone");
mktime(0,0,0,1,1,1970);
and also I tried:
date_default_timezone_set($timezone);
So the problems:
- For some dates, it seems to work fine. But on all our datetimes (stored as yyyy-mm-dd hh:mm:ss) it doesn't change them. They remain in the London timezone where the server is hosted
- Secondly, when inserting stuff into the database, we use:
$dateadded=date('Y-m-d H:i:s');
With the new timezone, it inserts it under their time (which is expected) but we don't want that to happen. All the times in the SQL database should be local to the server, and then output differently...
For the moment I've disabled all this to save it screwing up our database.
Any help is much appreciated. Thank you