3v4l.org

run code in 300+ PHP versions simultaneously
<?php ini_set('display_errors', 'on'); define('DAY_WORK', 32400); // 9 * 60 * 60 define('HOUR_START_DAY', '08:00:00'); define('HOUR_END_DAY', '17:00:00'); // get begin and end dates of the full period $date_begin = '2013-11-29 15:00:00'; $date_end = '2013-12-03 15:00:00'; // keep the initial dates for later use $d1 = new DateTime($date_begin); $d2 = new DateTime($date_end); // and get the datePeriod from the 1st to the last day $period_start = new DateTime($d1->format('Y-m-d 00:00:00')); $period_end = new DateTime($d2->format('Y-m-d 23:59:59')); $interval = new DateInterval('P1D'); //$interval = new DateInterval('weekdays'); // 1 day interval to get all days between the period $period = new DatePeriod($period_start, $interval, $period_end); $worked_time = 0; $nb = 0; // for every worked day, add the hours you want foreach($period as $date){ $week_day = $date->format('w'); // 0 (for Sunday) through 6 (for Saturday) if (!in_array($week_day,array(0, 6))) { // if this is the first day or the last dy, you have to count only the worked hours if ($date->format('Y-m-d') == $d1->format('Y-m-d')) { $end_of_day_format = $date->format('Y-m-d '.HOUR_END_DAY); $d1_format = $d1->format('Y-m-d H:i:s'); $end_of_day = new DateTime($end_of_day_format); $diff = $end_of_day->diff($d1)->format("%H:%I:%S"); $diff = split(':', $diff); $diff = $diff[0]*3600 + $diff[1]*60 + $diff[0]; $worked_time += $diff; } else if ($date->format('Y-m-d') == $d2->format('Y-m-d')) { $start_of_day = new DateTime($date->format('Y-m-d '.HOUR_START_DAY)); $d2_format = $d2->format('Y-m-d H:i:s'); $end_of_day = new DateTime($end_of_day_format); $diff = $start_of_day->diff($d2)->format('%H:%I:%S'); $diff = split(':', $diff); $diff = $diff[0]*3600 + $diff[1]*60 + $diff[0]; $worked_time += $diff; } else { // otherwise, just count the full day of work $worked_time += DAY_WORK; } } if ($nb> 10) die("die ".$nb); } echo sprintf('Works from %s to %s, You worked %d hour(s)', $date_begin, $date_end, $worked_time/60/60);
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught Error: Call to undefined function split() in /in/KQnBQ:36 Stack trace: #0 {main} thrown in /in/KQnBQ on line 36
Process exited with code 255.

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:
55 ms | 401 KiB | 8 Q