Support

Home Forums Event Espresso Premium espresso_event_date_obj() returning wrong event start date

espresso_event_date_obj() returning wrong event start date

Posted: December 15, 2014 at 10:53 am


Miguel Ángel García Martínez

December 15, 2014 at 10:53 am

Hi,

I’m using EE4 (latest update), and have set up two events for Jan 15, 2015. I added the following code to part of the sidebar of the event registration post:

$_event_date_obj = espresso_event_date_obj();
$_event_date = strtotime($_event_date_obj->start_date_and_time( 'D M jS', 'g:i a' ));
$_course_datetime = date("M", $_event_date) . " " . date("j", $_event_date) . ", " . date("Y", $_event_date);

However, instead of shown Jan 15, 2015, the date shown is Jan 16, 2014 (that is, 364 days of difference). I checked the event start date on both the admin area as well as the database itself, both have the correct value.

How can I fix this? Is this a bug?

PS: I saw in the release notes for the latest version that there was a bug with the start date when using UTC time. In my case, WordPress is configured to use UTC, but not sure if this is related, as it was not really fixed after the update.

Thanks in advance.
Miguel


Josh

  • Support Staff

December 15, 2014 at 1:49 pm

Hi Miguel,

It looks like the start_date_and_time() method is getting a date format passed in that will not disambiguate. The default date format is ‘F j, Y’, so if you don’t pass in a date format parameter it will use the default instead.

Can you try this instead?

$_event_date_obj = espresso_event_date_obj();
$_event_date = strtotime($_event_date_obj->start_date_and_time());
$_course_datetime = date("M", $_event_date) . " " . date("j", $_event_date) . ", " . date("Y", $_event_date);


Miguel Ángel García Martínez

December 15, 2014 at 3:39 pm

Excellent! Thanks Josh, it worked.

Miguel

The support post ‘espresso_event_date_obj() returning wrong event start date’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso