Support

Home Forums Event Espresso Premium Extracting the event length in days

Extracting the event length in days

Posted: March 28, 2017 at 6:38 am

Viewing 3 reply threads


Greenstones

March 28, 2017 at 6:38 am

I’m using the table template add-on to create a custom list of events. I’d like to have a new column that shows the number of days that an event lasts (our courses are 1 – 5 day in length).

I’m guessing that I need to subtract $datetime->start_date_and_time from datetime->end_date_and_time but I’m not having any luck. Any suggestions?


Josh

  • Support Staff

March 28, 2017 at 12:35 pm

Hi there,

The reason that you’re not able to get those two methods to work in a math equation is because those methods output strings. To do a calculation requires integers, so you could use the get_raw() method to get the timestamps in integers. Or you can use the EE_Datetime class’s length() method and it will return the length of the event’s date time and it will do the calculation for you.

e.g.
<?php echo $datetime->length('days'); ?>


Greenstones

March 29, 2017 at 12:31 am

Excellent. That worked perfectly!


Tony

  • Support Staff

March 29, 2017 at 4:55 am

Nice job, I’m glad that works for you 🙂

Viewing 3 reply threads

The support post ‘Extracting the event length in days’ 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