Counting working days excluding weekend

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.

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.