PDA

View Full Version : PHP/mySQL timezone issues



Mike
22-03-2010, 07:10 PM
Hi all,

My web server is based in the US somewhere. I've got info being inserted into mysql on the webserver, with a timestamp auto-updating. However when I display this info on my web page it shows it as being 2am instead of 8pm.

Can I:



somehow tell mySQL to add 18 hours when auto-updating the timestamp?
Tell PHP to treat the value coming from the timestamp field as date/time and add 18 hours (therefore often the next day)?

I don't appear to have access to the configuration to set my timezone. I am going to contact the webhost support to see if I have access to change this, but I'm not holding my breath...

Anyone have any suggestions?

Cheers,
Mike.

Mike
22-03-2010, 07:12 PM
P.S. mysql appears to be storing it as 'YYYY-MM-DD hh:mm:ss', whether that makes any difference (am I able to change that?)

Mike.

Erayd
22-03-2010, 07:39 PM
Use one of the many timezone-setting functions (e.g. date_default_timezone_set() (http://nz.php.net/manual/en/function.date-default-timezone-set.php)), or the date.timezone (http://nz.php.net/manual/en/datetime.configuration.php#ini.date.timezone) ini setting.

Mike
23-03-2010, 06:40 AM
Thanks Erayd, that pointed me in the right direction. I needed to convert the timestamp to unix-time or something first for it to work, and then everything has worked from there.

Cheers,
Mike.

Erayd
23-03-2010, 07:24 AM
:D