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('2018-06-01'); $end = new \DateTime('2018-06-15'); $days = work_days_between_two_dates($begin, $end); foreach ($days as $day) { echo $day->format('Y-m-d') . PHP_EOL; }
based on nBa8X
Output for 5.6.30, 7.0.30 - 7.3.0alpha1
2018-06-01 2018-06-02 2018-06-04 2018-06-05 2018-06-06 2018-06-07 2018-06-08 2018-06-11 2018-06-12 2018-06-13 2018-06-14 2018-06-15
Output for hhvm-3.18.5 - 3.22.0
2018-06-16 2018-06-16 2018-06-16 2018-06-16 2018-06-16 2018-06-16 2018-06-16 2018-06-16 2018-06-16 2018-06-16 2018-06-16 2018-06-16