entry_date is off by 4 hours
Posted: 22 June 2008 06:51 PM   [ Ignore ]
Newbie
Rank
Total Posts:  4
Joined  2008-05-06

Hi all -

In one of our templates, I am using some custom PHP to pull Freeform records, including entry_date. In the PHP, I display the entry_date like so:

echo "Subscribed on: " . date("g:i A O, F jS, Y", $subscriber_data["entry_date"]);

Oddly, the date that is displayed is off by four hours. For example, for a record entered at 8:24 PM on June 22nd, the above code displays: 12:24 AM -0500, June 23rd, 2008. What is odder still is that if I view the record within the EE control panel under Freeform’s Entries tab, it displays the date accurately (8:24). What am I doing wrong in my PHP code?

Thanks!

Profile
 
 
Posted: 22 June 2008 08:35 PM   [ Ignore ]   [ # 1 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  701
Joined  2004-03-30

Urban Turf,

You want to allow EE to adjust the timestamp in the DB for you. Most dates in EE are stored as timestamps, which you know. Those can be converted by EE on the fly into the timezone of the viewer looking at the page. Invoke the Localization class in your script

global $LOC;

Then use the method native to the class

$LOC->set_localized_time( $subscriber_data['entry_date'] );

Integrate that into your code and you should get correct times.

mk

 Signature 

Mitchell Kimbrough

Profile
 
 
Posted: 23 June 2008 04:46 AM   [ Ignore ]   [ # 2 ]
Newbie
Rank
Total Posts:  4
Joined  2008-05-06

Mitchell -

Thanks for the prompt reply—and the perfect answer. It worked like a charm!

Just to confirm, the times I was seeing were GMT, right? (I initially thought this to be the case, but then decided it against it, because I’ve always thought I was -5 hours from GMT. Turns out I’m -4 after all! I guess because of DST...?)

Profile
 
 
   
 
 
‹‹ Count Entries      "From" Email ››