I have the following code calculating the total amount of business days: (working)
<?php
//get current month for example
if(!isset($_GET['from'])) {
$beginday=date("Y-m-01");
} else {
$beginday=date($_GET['from']);
}
if(!isset($_GET['to'])) {
$lastday=date("Y-m-01");
} else {
$lastday=date($_GET['to']);
}
$nr_work_days = getWorkingDays($beginday,$lastday);
echo $nr_work_days;
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++; // no of days in the given interval
$what_day=date("N",$begin);
if($what_day>5) { // 6 and 7 are weekend days
$weekends++;
};
$begin+=86400; // +1 day
};
$working_days=$no_days-$weekends;
return $working_days;
}
}
?>
What i miss now is the feature that cuts out all the public holidays. Any suggestions whats the best way to perform this?