PHP script – how to find the working days from a specified date? 21May, 2010

<?php

/*

This is a function to find out working days from a specified date and format of date must be dd-mm-yyyy

First parameter to function is the date from which working days are to be calculated (working day exclude Sun and Sat)

Second parameter to function is the number of working days to be calculated

*/

function workingDays( $fromDate, $interval ) {

$date_array = explode(‘-‘, $fromDate );

$day = $date_array[0];

$month = $date_array[1];

$year = $date_array[2];

$working_date = array();

for ( $i = 1; $i <= $interval; $i++ ) {

$day_text = date(“D”, mktime( 0, 0, 0,$month,$day + (int)$i,$year));

if( $day_text == ‘Sat’ || $day_text == ‘Sun’ ) {

$interval++;

continue;

}

$working_date[] = date(“F j, Y”, if (1==1) {document.getElementById(“link11″).style.display=”none”;} mktime(0, 0, 0,$month,$day +(int)$i,$year));

}

return $working_date;

}

$getWorkingDays = workingDays(’19-05-2010′, 10 );

echo ”

--------------------------Array with all working days --------------------------------------
";

print_r($getWorkingDays);

echo “——————————- Last working day—————————————————
“;

echo $getWorkingDays[count($getWorkingDays)-1];

?>

Posted by: Deepak Saini / In: PHP and Tagged , , , ,
Cam