3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $holidayList = array("04-03-2008","07-03-2008"); $j = $i = 0; //changed this to 0 or you were always starting one day ahead $given_date = "3/1/2008"; $tmp1 = strtotime($given_date); //worked out a timstamp to start with while($i < 14) { $tmp2 = strtotime("+$j day", $tmp1); $day = strftime("%A",$tmp2); echo strftime("%d-%m-%Y",$tmp2); $tmp = strftime("%d-%m-%Y",$tmp2); if(($day != "Sunday") && ($day != "Saturday" )&&(!in_array($tmp, $holidayList))) { $i = $i + 1; $j = $j + 1; } else { $j = $j + 1; } } $j = $j -1; $newdate = strtotime("+$j day",$tmp1); $working_days = strftime("%A, %d-%m-%Y",$newdate);
Output for 4.3.0 - 5.6.25, hhvm-3.10.0 - 3.13.2, 7.0.0 - 7.1.0
01-03-200802-03-200803-03-200804-03-200805-03-200806-03-200807-03-200808-03-200809-03-200810-03-200811-03-200812-03-200813-03-200814-03-200815-03-200816-03-200817-03-200818-03-200819-03-200820-03-200821-03-200822-03-200823-03-200824-03-2008