Friday, April 21, 2017

Php add days to current date excluding weekends and excluding holidays

<?php

$holidayDates = array(
    '2016-03-26',
    '2016-03-27',
    '2016-03-28',
    '2016-03-29',
    '2017-04-25',
);

$count5WD = 0;
$temp = strtotime("2017-04-21");

while($count5WD<2){
    $next1WD = strtotime('+1 weekday', $temp);
    $next1WDDate = date('Y-m-d', $next1WD);
    if(!in_array($next1WDDate, $holidayDates)){
        $count5WD++;
    }
    $temp = $next1WD;
}

$next5WD = date("Y-m-d", $temp);

echo $next5WD;
?>