Support

Home Forums Event Espresso Premium How can I display end dates using Event Table addon?

How can I display end dates using Event Table addon?

Posted: March 1, 2017 at 4:05 am


greyowl

March 1, 2017 at 4:05 am

I have events with multiple dates. I use the toggle template and have made changes to it to show ‘from … to …’ as follows:
$datetimes = EEM_Datetime::instance()->get_datetimes_for_event_ordered_by_start_time( $post->ID, $show_expired, false, $datetime_limit );

// Reset the datetimes pointer to the earlest datetime and use that one.
$datetime = reset( $datetimes );
?>
<tr class=”espresso-table-row <?php echo $category_slugs; ?>”>
<td class=”event_title event-<?php echo $post->ID; ?>”><?php echo $post->post_title; ?></td>
<td class=”venue_title event-<?php echo $post->ID; ?>”><?php espresso_venue_name( NULL, FALSE ); ?></td>
<td class=”start_date event-<?php echo $post->ID; ?>”
data-value=”<?php echo $datetime->get_raw( ‘DTT_EVT_start’ ); ?>”>
<ul class=”ee-table-view-datetime-list”>
von <?php
// Loop over each datetime we have pulled from the database and output
foreach ($datetimes as $datetime) {
?>
<?php echo date_i18n( $date_format . ‘ ‘ . $time_format, strtotime( $datetime->start_date_and_time(‘Y-m-d’, ‘H:i:s’) ) ); ?>
<?php
//end foreach $datetimes
}
?> bis
<?php
// Loop over each datetime we have pulled from the database and output
foreach ($datetimes as $datetime) {
?>
<?php echo date_i18n( $date_format, strtotime( $datetime->end_date() ) ); ?>
<?php
//end foreach $datetimes
}
?>

</td>
<td class=”event_content event-<?php echo $post->ID; ?>”><?php espresso_event_content_or_excerpt(); ?></td>
<td class=”td-group reg-col” nowrap=”nowrap”><?php echo $live_button; ?></td>
</tr>

This only shows the start date and time, followed again by the start date (instead of the end date). I don’t understand the logic of the loop. Can someone help, please?
Veranstaltungsort: Wohlen (Ref. Kirche)
Datum: von 2. März 9:00 bis 2. März
Beschreibung: Auszug


Tony

  • Support Staff

March 1, 2017 at 6:50 am

This line:

echo date_i18n( $date_format, strtotime( $datetime->end_date() ) );

Will only output the end DATE and not the time. So if the datetime start date and end date are on the same day it will look like its outputting the start date, but it’s not.

Change that to use:

echo date_i18n( $date_format . ‘ ‘ . $time_format, strtotime( $datetime->end_date_and_time(‘Y-m-d’, ‘H:i:s’) ) );

And that should work.

However, that code is going to loop over all of the datetime within an event and output the start dates, then AFTER that loop over all of the datetimes and output the end dates.

So if you have 3 datetime in an event you would end up with something like this:

March 1, 2017 8:00 am
March 2, 2017 8:00 am
March 3, 2017 8:00 am

To

March 1, 2017 5:00 pm
March 2, 2017 5:00 pm
March 3, 2017 5:00 pm

Is that how you want to output the details?

March 1, 2017 8:00 am to March 1, 2017 5:00 pm
March 2, 2017 8:00 am to March 2, 2017 5:00 pm
March 3, 2017 8:00 am to March 3, 2017 5:00 pm


greyowl

March 1, 2017 at 9:18 am

Thanks, Tony, for taking me seriously and taking the trouble to respond. But your solution is not quite right, I’m afraid. My event called ‘Kurs 1’ has a whole series of dates:
20. März 13:30 – 15:10
23. März 09:00 – 10:50
27. März 13:30 – 15:10
30. März 09:00 – 10:50
3. April 13:30 – 15:10
6. April 09:00 – 10:50
10. April 13:30 – 15:10
13. April 09:00 – 10:50
17. April 13:30 – 15:10
20. April 09:00 – 10:50
24. April 13:30 – 15:10
27. April 09:00 – 10:50

But when I expand the toggle, I only see the first date, both for start and end:
Veranstaltungsort: Wohlen (Ref. Kirche)
Datum: von 20. März 13:30 bis 20. März
Beschreibung: Auszug

I don’t get a list of dates. I suspect the line:
$datetime = reset( $datetimes );
means it only sees the first date, so the loop is really doing nothing.

Also, the date and time formats (‘Y-m-d’, ‘H:i:s’) seem to be ignored, because they are overridden by the $date_format . ‘ ‘ . $time_format, which I’d like to be able to modify but I don’t know their structure.

I’d very much appreciate some help with this code.


Tony

  • Support Staff

March 1, 2017 at 9:38 am

$datetime = reset( $datetimes );

Resets the pointer of the $datetimes array and returns the first element from the array, that’s unlikely to be your problem.

By default the table template only pulls (and displays) a single datetime, have you added show_all_datetimes=true to the shortcode your using?

That tells the template to pull all datetimes.

Take a look here for a list of available parameters:

https://eventespresso.com/wiki/events-table-view-template-add-on/

Also, the date and time formats (‘Y-m-d’, ‘H:i:s’) seem to be ignored, because they are overridden by the $date_format . ‘ ‘ . $time_format, which I’d like to be able to modify but I don’t know their structure.

Its not ignored, its intentional set that way to make sure the correct format is output in the end.

$date_format and $time_format will use your sites current date and time formats set within Dashboard -> Settings -> General.

You can override them by passing your own formats in place of those variables, the format used is shown here:

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


greyowl

March 1, 2017 at 10:11 am

OK, were getting there! Thanks, Tony. I’ve added the ‘show_all_datetimes=true’ and now understand how to format date and time. But now the start dates of all appointments are listed, then all the end dates. So I now need to find a way of displaying only the start date of the first appointment and the end date of the last appointment. Any suggestions?


Tony

  • Support Staff

March 1, 2017 at 4:15 pm

So I now need to find a way of displaying only the start date of the first appointment and the end date of the last appointment. Any suggestions?

That’s expected with the current code, pulls in all of the datetimes and your looping over all of them to output the dates from each.

To do what your looking to do you need to completely change the code used for the datetime output (the loops your using).

You’ll need something like:

$earliest_event_date = EEH_Event_View::the_earliest_event_date( $date_format, '', $EVT_ID );
$latest_event_end_date = EEH_Event_View::the_latest_event_date( $date_format, '', $EVT_ID );

Then those two variables contain the dates you need to output in the format you’ve provided within $date_format for each.


greyowl

March 2, 2017 at 1:20 am

Fantastic! How can I thank you, Tony?


Tony

  • Support Staff

March 2, 2017 at 4:06 am

No need to thank me 🙂

However it would be greatly appreciated if you could share your Event Espresso experience in a review.

The support post ‘How can I display end dates using Event Table addon?’ 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