PHP script – how to find the working days from a specified date?

Posted by Deepak Saini on in PHP

<?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”, mktime(0, 0, 0,$month,$day +(int)$i,$year));

}

return $working_date;

}

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

echo “<pre>————————–Array with all working days ————————————–<br/>”;

print_r($getWorkingDays);

echo “——————————- Last working day—————————————————<br/>”;

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

?>



Tags: , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Powered by WP Hashcash

bottombar