Counting working days excluding weekend
The following example illustrates how to calculate working days excluding week end days.
<?
function count_woking_days($date_start,$date_end){
$workdays = 5;
$firstdate = strtotime($date_start);
$lastdate = strtotime($date_end);
//get the day of the date
$firstday = date(w,$firstdate);
$lastday = date(w,$lastdate);
//get the week of the date
$firstweek = date(W,$firstdate);
$lastweek = date(W,$lastdate);
if($lastday > $workdays){
$lastday = $workdays;
}
if($lastday >= $firstday){
$leftday = $lastday - $firstday;
}else{
$leftday = $firstday - $lastday;
}
$diffweeks = $lastweek - $firstweek;
$dayinweeks = $diffweeks * $workdays;
return $totaldays = $dayinweeks + $leftday + 1;
}
$from_date = “2007-02-14″;
$to_date = “2007-02-28″;
echo count_woking_days($from_date,$to_date);
?>
In above example we can pass starting and ending date to “count_working_days()” function. In that funtion, we can calculate the totaldays except week end days.
