3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function work_days_between_two_dates(\DateTime $begin, \DateTime $end) { $workdays = []; $all_days = new DatePeriod($begin, new DateInterval('P1D'), $end->modify('+1 day')); foreach ($all_days as $day) { $dow = (int)$day->format('w'); $dom = (int)$day->format('j'); if (1 <= $dow && $dow <= 5) { // Mon - Fri $workdays[] = $day; } else if (6 == $dow && 0 == $dom % 2) { // Even Saturday $workdays[] = $day; } } return $workdays; } $begin = new \DateTime('2015-11-01'); $end = new \DateTime('2015-11-14'); $days = work_days_between_two_dates($begin, $end); foreach ($days as $day) { echo $day->format('Y-m-d') . PHP_EOL; }
based on khZSa
Output for 5.4.0 - 5.6.30, 7.0.0 - 7.3.1
2015-11-02 2015-11-03 2015-11-04 2015-11-05 2015-11-06 2015-11-09 2015-11-10 2015-11-11 2015-11-12 2015-11-13 2015-11-14
Output for hhvm-3.10.1 - 3.22.0
2015-11-15 2015-11-15 2015-11-15 2015-11-15 2015-11-15 2015-11-15 2015-11-15 2015-11-15 2015-11-15 2015-11-15 2015-11-15
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/vrhsa on line 4
Process exited with code 255.
Output for 5.1.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/vrhsa on line 3 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/vrhsa on line 3 Parse error: syntax error, unexpected '[' in /in/vrhsa on line 4
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/vrhsa on line 3 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/vrhsa on line 3 Parse error: parse error, unexpected '[' in /in/vrhsa on line 4
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/vrhsa on line 3 Parse error: syntax error, unexpected T_STRING, expecting ')' in /in/vrhsa on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/vrhsa on line 3 Parse error: parse error, unexpected T_STRING, expecting ')' in /in/vrhsa on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/vrhsa on line 3 Parse error: parse error, expecting `')'' in /in/vrhsa on line 3
Process exited with code 255.