Below is my code

function getWorkingDays($startDate, $endDate){
 $begin=strtotime($startDate);
 $end=strtotime($endDate);
 if($begin>$end){
  echo "startdate is in the future! <br />";
  return 0;
 }else{
   $no_days=0;
   $weekends=0;
  while($begin<=$end){
    $no_days++; 
    $what_day=date("N",$begin);
     if($what_day>5) { 
          $weekends++;
     };
    $begin+=86400; 
  };
  $working_days=$no_days-$weekends;
  return $working_days;
 }
}



$beginday=date("2016-04-01");
$lastday=date("2016-06-30");

$nr_work_days = getWorkingDays($beginday,$lastday);
echo $nr_work_days;
?>

above code is giving count for excluding saturday and sunday, and working fine.

then
i need one help.

how i need to pass array like public holidays list,
then exclude the public holiday then return the count of working days.

Try:

function getWorkingDays($startDate, $endDate, $holidayList)
{
    $working_days = 0;
    $begin = strtotime($startDate);
    $end = strtotime($endDate);
    if($begin > $end)
    {
        echo "startdate is in the future! <br />";
    }
    else
    {
        foreach($holidayList as $k=>$v)
        {
            $holidayList[$k] = strtotime($v);
        }

        $no_days = 0;
        $weekends = 0;
        $holidays = 0;
        while($begin <= $end)
        {
            $no_days++;
            $what_day = date("N", $begin);
            if($what_day > 5)
            {
                $weekends++;
            }
            elseif( in_array($begin,$holidayList) )
            {
                $holidays++;
            }
            $begin += 86400;
        };
        $working_days = $no_days - ($weekends + $holidays);
    }
    return $working_days;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.