3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data =array( array ( 'ticketCreated' => '2020-02-03 15:59:30','ticketCompletedOn' => '2020-02-04 09:53:35'), array ( 'ticketCreated' => '2020-02-04 14:00:00', 'ticketCompletedOn' => '2020-02-04 14:36:00') ); $sum_time = 0; foreach($data as $details){ $start_time = new DateTime($details['ticketCreated']); $end_time = new DateTime($details['ticketCompletedOn']); $end_of_day = new DateTime($start_time->format('Y-m-d') . ' 17:00:00'); // since a day ends at 17:00 do{ $diff = $end_time->diff($start_time); $diff2 = $end_of_day->diff($start_time); if($end_time->format('Y-m-d') === $start_time->format('Y-m-d')){ // meaning finished on the same day $sum_time += ($diff->h * 60) + ($diff->i) + ($diff->s / 60); }else if(!in_array($end_of_day->format('N'),[6,7])){ // skipping Saturdays and Sundays $sum_time += ($diff2->h * 60) + ($diff2->i) + ($diff2->s / 60); // add the day's offset(480 minutes) } $end_of_day->add(new DateInterval('P1D')); $start_time = new DateTime($end_of_day->format('Y-m-d') . ' 09:00:00'); // start time for next day which is 09:00 }while($start_time <= $end_time); } $avg = $sum_time / count($data); echo "$avg minutes",PHP_EOL;
Output for git.master, git.master_jit, rfc.property-hooks
75.041666666667 minutes

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
114.27 ms | 405 KiB | 5 Q