Timestamp

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
thoughtriot
Forum Commoner
Posts: 26
Joined: Thu Nov 07, 2002 9:32 pm

Timestamp

Post 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?
Rob the R
Forum Contributor
Posts: 128
Joined: Wed Nov 06, 2002 2:25 pm
Location: Houston

Post 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. :wink:
User avatar
BigE
Site Admin
Posts: 139
Joined: Fri Apr 19, 2002 9:49 am
Location: Missouri, USA
Contact:

Post 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.
Post Reply