Event Duration
-
Further to this. Initially I created a custom attribute but if certain criteria caused the length to change I’d have to change the finish time any way so wanted to automate. Plus I have no coding experience so its good to have a go to get an understanding, I bodged it together from the web, but it works.
Using the start and finish times of your event I created a shortcode to show event duration in XhY.
Hope it helps someone else.
function em_event_duration(){ $day = 0; $hour = 0; $minute = 0; $date1 = do_shortcode("[event]#_{Y-m-d H:i}[/event]"); $date2 = do_shortcode("[event]#@_{Y-m-d H:i}[/event]"); $datetimeObj1 = new DateTime($date1); $datetimeObj2 = new DateTime($date2); $interval = $datetimeObj1->diff($datetimeObj2); if($interval->format('%d') > 0){ $day = $interval->format('%d')*24; } if($interval->format('%h') > 0){ $hour = $interval->format('%h'); } if($interval->format('%I') > 0){ $minute = $interval->format('%I'); } return ($day + $hour) . "h" . $minute; } add_shortcode ( 'ev-dur', 'em_event_duration' );
- The topic ‘Event Duration’ is closed to new replies.