I am trying to calculate number of week days (monda-friday) in a given date range using PHP. If the user enters the start (2010-12-01) and end date (2010-12-24), the function should spit out number of week days within that date range.
This is what I found but it doesnt help..
function getworkingdays_time($STARTSTAMP, $ENDSTAMP){
$noofdays = ceil(($ENDSTAMP - $STARTSTAMP) / 86400);
$sundaycounter = 0;
$saturdaycounter = 0;
$holidaycounter = 0;
$offset = 0;
$holidaycounter = check_holiday_range($STARTSTAMP, $ENDSTAMP); // check holiday range
if(!defined("WORKSATURDAYS"))
{
define("WORKSATURDAYS", 0);
}
if(!defined("WORKSUNDAYS"))
{
define("WORKSUNDAYS", 0);
}
for ($i = 0; $i <= $noofdays; $i++){
$ts = $STARTSTAMP + ($i * 86400);
if (WORKSATURDAYS == '0' && date("l", $ts) == "Saturday"){
## they dont work saturdays
$saturdaycounter ++;
} elseif (WORKSUNDAYS == '0' && date("l", $ts) == "Sunday"){
## they dont work sundays
$sundaycounter ++;
}
}
$total = $holidaycounter + $saturdaycounter + $sundaycounter;
$offset = $total;
if ($total > 0){
$total = getworkingdays_time($ENDSTAMP + 86400, ($ENDSTAMP + ($total * 86400) + 86400));
$offset += $total;
}
unset($holidaycounter, $saturdaycounter, $sundaycounter, $i, $noofdays, $ts, $total);
return ($offset);
}
Any help will be greatly appreciated. Thanks heaps PSi