PHP Snippet 1:
echo getWorkingDays("2022-04-01","2022-04-30",6);
function getWorkingDays($startDate,$endDate,$working_days_in_a_week){
// do strtotime calculations just once
$endDate = strtotime($endDate);
$startDate = strtotime($startDate);
$start_day = date("N", $startDate);
//The total number of days between the two dates. We compute the no. of seconds and divide it to 60*60*24
//We add one to inlude both dates in the interval.
$days = ($endDate - $startDate) / 86400 + 1;
$fullweeks = floor($days/7);
$restofdays = $days%7;
$workingDays=$fullweeks*$working_days_in_a_week;
for($x=0;$x<$restofdays;$x++){
if((($start_day+$x)%7)<=$working_days_in_a_week)$workingDays++;
}
return $workingDays;
}