Click to See Complete Forum and Search --> : Timezone in MySQL DATE_FORMAT?


Joseph Witchard
12-01-2008, 11:39 PM
My webhost resides in Californina, and I'm in CST. So, all of the time that comes out of MySQL is in pacific time. BUT, my message board goes by CST, and I'd really like for them to go together. Is there anyway to choose a timezone in MySQL's DATE_FORMAT()?

felgall
12-01-2008, 11:50 PM
You would store the times in the database in whatever timezone you want. It would probably be easiest if you just set the timezone for all your scripts to use the one you want so that the scripts all run on your timezone rather than California.

Joseph Witchard
12-01-2008, 11:58 PM
How would I do that using PHP? I read something about it on PHP's website, but I didn't really understand it, and one of the places I was in on php.net (a place that listed the different timezones, but I'm not sure which one) said don't use any of these timezone except for UTC.

felgall
12-02-2008, 03:07 AM
In PHP you'd add one of these to the top of your script.

putenv("TZ=America/Chicago");
putenv("TZ=America/Menominee");

Alternatively if you have access to the php.ini file add the following line there instead to change it for all the PHP scripts:

date.timezone = "America/Chicago"

Joseph Witchard
12-02-2008, 05:57 PM
I don't have access to php.ini.

Is there a way to use UTC, but like, somehow let it know that it's supposed to be CST? I tried UTC-5, but it didn't work.

felgall
12-02-2008, 07:26 PM
I don't have access to php.ini.

So use the putenv statement at the top of your PHP.

Joseph Witchard
12-02-2008, 09:48 PM
All right, thanks!