Support

Home Forums Event Espresso Premium How do I echo out the start date – time / end date time?

How do I echo out the start date – time / end date time?

Posted: August 11, 2015 at 10:48 pm


Judy

August 11, 2015 at 10:48 pm

Hello!
Currently I am editing the custom event table list plugin for EE3.

The code I am using to display start date and start time is:
<?php echo event_date_display($event->start_date.’ ‘.$event->start_time, get_option(‘date_format’).’ ‘.get_option(‘time_format’)) ?>

Which returns the following:
September 21, 2015 1:00 pm

What I am looking to accomplish is a format like this:
Sept 21 – Sept 28th, 2015 from 1:00pm to 3:00pm

I wanted to specifically list the start dates in a shortened format (sept 21 – Sept 28th, 2015) followed by the event start time – end time. Exactly like I have written above.
Could someone please kindly assist in helping me figure out how to write this code for my template? I have struggled for quite some time trying to figure this out.

Thanks kindly!


Dean

August 12, 2015 at 6:22 am

Hi,

This is a little verbose, but hopefully it will explain it to you better:

//start date
$sd = event_date_display($event->start_date, 'j M');
//start date year
$sdy = event_date_display($event->start_date, 'Y');
//end date
$ed = event_date_display($event->end_date, 'j M');
//start time
$st = event_date_display($event->start_time, get_option('time_format'));
//end time
$et = event_date_display($event->end_time, get_option('time_format'));

//bring it all together
echo "<p>";
echo $sd . ' - ' . $ed . ', ' . $sdy . ' from ' . $st . ' to ' . $et;
echo "</p>";

So you use the event_date_display function, and give that function the “date” (includes time) and a format, it will then provide the appropriate info.

The above will result in:

21 Sep – 28 Sep, 2015 from 1:00 pm to 3:00 pm

Please note Sept is not possible, it’s either Sep or September, or numerical.


Judy

August 14, 2015 at 1:52 pm

Thank you very much Dean,
This worked absolutely flawlessly!

The support post ‘How do I echo out the start date – time / end date time?’ 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