Support

Home Forums Event Espresso Premium Display Event Start / End Time in Event Post

Display Event Start / End Time in Event Post

Posted: November 26, 2013 at 5:48 pm


Sean Collishaw

November 26, 2013 at 5:48 pm

Hello EE Folks! I’ve got another question about displaying the Event Start / End time. Right now, I have the following in my event_post.php file (in the templates directory, of course):

<p><?php echo date(‘l M jS, Y g:i a’,strtotime($start_date)) . ” – ” . date(‘l M jS, Y g:i a’,strtotime($end_date)); ?></p>

This is displaying the proper format (Friday Nov 29th, 2013 12:00 am) but the start and end time display as 12:00 am even though there is a defined start / end time. What do I need to do in order to show the start / end time properly?

Thanks!


Dean

November 27, 2013 at 2:26 am

Hi,

This is because the start date and start time are separate, so you are trying to display the time on something that doesn’t have it or has the default.

I would use this instead

<?php echo event_date_display($start_date, get_option('date_format'));
echo " "; //just a space
echo event_date_display($event->start_time, get_option('time_format'));
echo " - ";
echo event_date_display($end_date, get_option('date_format'));
echo " "; //just a space
echo event_date_display($event->end_time, get_option('time_format')); 
?>

You can replace the get_option(‘date_format’) with (‘m/d/Y’) etc.


Sean Collishaw

November 27, 2013 at 4:33 pm

Thanks Dean!

That’s now displaying the Start / End as “11/29/2013 – 11/29/2013” (http://www.climbcrux.org/2013/10/friday-night-climb-at-brooklyn-boulders-nov-29-2013/) and still not showing the start / end times.

Also, if I wanted to change the format of the date to be “Friday Nov 11th, 2013” rather than “11/29/2013” how do I do that? I tried replacing (‘date_format’) with (‘l M jS, Y’) but that did not work. πŸ™‚


Dean

November 28, 2013 at 1:16 am

Odd, it’s working for me – http://d.pr/i/zf07

Format wise, instead of

echo event_date_display($end_date, get_option('date_format'));

it would be

echo event_date_display($end_date, ('d-m-Y');


Sean Collishaw

November 29, 2013 at 4:29 pm

Hey Dean… Still no Start / End times. I’ve updated the date format, and that’s working, but no start / end times. Here’s the code I have:

<code>&lt;/php /* the below section changed to include the event start and event end time when looking at event posts */ ?&gt;
&lt;?php echo event_date_display($start_date, (&#039;l M jS, Y&#039;));
echo &quot; &quot;; //just a space
echo event_date_display($event-&gt;start_time, get_option(&#039;time_format&#039;));
echo &quot; - &quot;;
echo event_date_display($end_date, (&#039;l M jS, Y&#039;));
echo &quot; &quot;; //just a space
echo event_date_display($event-&gt;end_time, get_option(&#039;time_format&#039;));
?&gt;</code>

I’m working on one event for now until I get this right. If you look at the calendar (http://www.climbcrux.org/eventscalendar) for November 29th, there’s an event from 7pm – 10pm. When you click that event, it shows the Date / Time as “Friday Nov 29th, 2013 – Friday Nov 29th, 2013”

Could there be a setting somewhere I’m missing?


Dean

December 2, 2013 at 3:46 am

Hi,

I’m just not sure why it isn’t working for you. I added the above code to a new site running the latest EE (though your version will be the same) and it gave me this http://d.pr/i/sx15 so the code works, settings shouldn’t be an issue here.

If you can add the entire template code to a pastebin (http://pastebin.com/) I can add it to a test site and maybe there is something else in your code that is making this not work.

I am assuming you are adding this to the event_registration_page_display.php file?


Sean Collishaw

December 2, 2013 at 8:57 pm

Hi Dean… I think we’ve found the issue. πŸ™‚ The Registration Page works just fine (http://www.climbcrux.org/event-registration/?ee=233). What I’m trying to do is add the Start / End time to the WordPress event post, not the registration page. I’ve had several people complain that when we link to the event post, on Facebook for instance, the post itself has no start / end time; users have to go to the registration page to see that information. (Event Post — http://www.climbcrux.org/2013/10/crux-first-fridays-friday-night-climb-at-brooklyn-boulders-new-climbers-welcome-2/)

Am I correct that if I want to modify the way the WordPress post is created, I should be making these changes to event_post.php?


Dean

December 3, 2013 at 2:16 am

Hi,

I am sorry I completely missed that!

Yes the event_post.php needs to be edited, something liek this at line 274

<p><?php echo event_date_display($start_date, get_option('date_format')) . " " . $data->event->start_time . " - " . event_date_display($end_date, get_option('date_format')) . " " . $data->event->end_time; ?></p>

You will need to update the Event before the post will reflect any changes.


Sean Collishaw

December 5, 2013 at 9:26 am

Hi Dean, we’re almost there! Now the last question is how to update the format for the time from 24hr time to 12hr time. Right now I’m seeing 19:00 – 22:00 rather than 7pm – 10pm, and I don’t see in the code you provided any way to modify the display format for the time.

Thanks!


Dean

December 6, 2013 at 2:39 am

Hi,

You will need to use the Date format (works for time too)

http://php.net/manual/en/function.date.php

<p><?php echo event_date_display($start_date, get_option('date_format')) . " " . date('h:i a', strtotime($data->event->start_time)) . " - " . event_date_display($end_date, get_option('date_format')) . " " . date('h:i a', strtotime($data->event->end_time)); ?></p>


Sean Collishaw

December 6, 2013 at 9:46 am

Dean, you’re the best! I knew I had to update the Date format display, but wasn’t sure what the PHP code to do that was. The $data->event->end_time was giving me fits.

It’s all fixed now though. Thanks so much!

The support post ‘Display Event Start / End Time in Event Post’ 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