Page 1 of 1
Timestamp
Posted: Wed Nov 27, 2002 11:05 pm
by thoughtriot
Okay I'm making a news blog type thing using a database, and I have a field called Date, which is a timestamp(14) and it displays the date/time the entry was added/edited. I then used this to make the timestamp show the date in the format I wanted:
Code: Select all
$Date = stripslashes($resultї"DATE_FORMAT(Date, '%m.%d.%y %h:%i %p')"]);
The only problem is that it displays the date 3 hours ahead of the date where I live. How would I make it so it displays my date's timezone, which is -3 from what it's showing currently?
Posted: Mon Dec 02, 2002 8:52 am
by Rob the R
Since PHP is executed on the server, it can't directly return the local time zone of the user. You'd have to use some Javascript in combination with PHP to do what you want. I found a reference to such a technique at this website:
http://martin.f2o.org/php/localtime
but I have not tried it myself, so I can't make any claims to its usefulness or correctness.
Now, if you don't care to try to determine what the user's time zone is, you can just subtract three hours from the server time (using the mktime() function) to get your local time. This assumes that you'll always be accessing your east-coast-hosted website from your west coast home.

Posted: Mon Dec 02, 2002 10:21 am
by BigE
I suppose you could do something in your query to subtract 3 hours from it... also, if you could pull it out of the DB in a Unix Timestamp format, you can do something similar to the following
Code: Select all
<?php
$date = date('format', ($result['timestamp'] -10800));
?>
Hope that helps.