- strftime: documentation ( source)
- in_array: documentation ( source)
- strtotime: documentation ( source)
<?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 = "04/09/2013 13:06:00";
$tmp1 = strtotime($given_date); //worked out a timstamp to start with
while($i < 5)
{
$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);
echo $working_days = strftime("%A, %d-%m-%Y",$newdate);