Page 1 of 1

Timestamp Timezone problems

Posted: Thu Jun 30, 2005 8:37 pm
by Sculpture
Hello,

I have looked at MySQL forums regarding timezones. My site is hosted in the US and I need to see results in the database in Australia. Needless to say the time will be at least 12 hours late. I have come to the conclusion that there is no way to amend the database, so is there a way to do it with PHP?

Thanks

Posted: Fri Jul 01, 2005 12:34 am
by Burrito
just add or subtract the hours for the given timezone using strtotime()

ex:

Code: Select all

$mountaintime = -8; //gmt - 8 hours for mountain standard time
$datetime = "06/30/2005 10:00:00";
echo date("m/d/Y g:i a", strtotime($datetime." ".$mountaintime." hours"));

Posted: Fri Jul 01, 2005 12:55 am
by Sculpture
Thank you for your help.

Please excuse my lack of understanding, I pasted the code where I think it should have been, between the php tags in the heading and it now displays the time, (ajusted), on the page. How do I manage to get that inserted into the timestamp column in the database?

Posted: Fri Jul 01, 2005 2:03 am
by Burrito
you'll have to update your table:

ex:

Code: Select all

$mountaintime = -8; //gmt - 8 hours for mountain standard time
$datetime = "06/30/2005 10:00:00";
$adjusted = date("Y-m-d g:i a", strtotime($datetime." ".$mountaintime." hours"));
mysql_query("update myTable set myDatetimefield = '$adjusted'")
  or die(mysql_error());

Posted: Mon Jul 04, 2005 6:39 pm
by Sculpture
Thanks again Burrito!

This time the code didn't produce anything. May well be the way I am applying it. I assume ($mountaintime) is a made up variable? Just trying to get my head around the method.

Thanks again.

Posted: Mon Jul 04, 2005 6:49 pm
by Burrito
yes $mountaintime is just a variable that I assigned the value of -8. I believe MST is GMT - 8 hours...