3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $objToday = new Datetime(); $objFirstOfMonth = new DateTime('first day of this month'); $intNumberOfWorkDays = 0; $obj1Day = new DateInterval('P1D'); while ($objToday >= $objFirstOfMonth && $intNumberOfWorkDays <= 5) { if ($objFirstOfMonth->format('N') < 6) { $intNumberOfWorkDays++; } //echo sprintf('%s:%s', $intNumberOfWorkDays, $objFirstOfMonth->format('N d.m.Y')) . "\r\n"; $objFirstOfMonth = $objFirstOfMonth->add($obj1Day); } if ($intNumberOfWorkDays == 5) { echo 'Boooyaaah!'; } else { echo $intNumberOfWorkDays; }
based on lPq0J
Output for 7.1.0 - 7.2.6
3
Output for 5.3.19 - 5.4.45, 5.6.28, 7.0.20
4
Output for 7.0.6
2
Output for 5.5.30, 5.6.14, 5.6.21, 7.0.5
1
Output for 5.5.24 - 5.5.29, 5.5.31 - 5.6.13, 5.6.15 - 5.6.20, 7.0.0 - 7.0.4
6