Timestamp Timezone problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Sculpture
Forum Commoner
Posts: 41
Joined: Sat Jun 11, 2005 6:57 pm
Location: Australia
Contact:

Timestamp Timezone problems

Post 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
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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"));
User avatar
Sculpture
Forum Commoner
Posts: 41
Joined: Sat Jun 11, 2005 6:57 pm
Location: Australia
Contact:

Post 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?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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());
User avatar
Sculpture
Forum Commoner
Posts: 41
Joined: Sat Jun 11, 2005 6:57 pm
Location: Australia
Contact:

Post 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.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

yes $mountaintime is just a variable that I assigned the value of -8. I believe MST is GMT - 8 hours...
Post Reply