About Deepak Saini

  • Website: or email
  • Biography:

Posts by Deepak Saini:

 
0

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

on May 21, 2010 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: , , , ,

bottombar