I have a script to count working days between 2 dates. Actually I need extra function to script count date when 14 working days will pass.
For example: start date will be “2010-04-18”, so I want to script count that after 14 working days it will be “2010-05-07”.
My code:
[code=php]
<?php
function workDays($date1, $date2, $withStartDay = false) {
$date1=strtotime($date1);
$date2=strtotime($date2);
if ($date2===$date1 && !$withStartDay) return 0;
$char=1;
if ($date1>$date2)
{$datePom=$date1;$date1=$date2;$date2=$datePom;$char=-1;}
$count=0;
if (!$withStartDay)
$date1=strtotime(‘+1 day’,$date1);
$date2=strtotime(‘+1 day’,$date2);
$lastYear = null;
$hol=array(’01-01′,’05-01′,’05-03′,’08-15′,’11-01′,’11-11′,’12-25′,’12-26′);
while ($date1<$date2) {
$year = date(‘Y’, $date1);
if ($year !== $lastYear){
$lastYear = $year;
$easter = date(‘m-d’, easter_date($year));
$date = strtotime($year . ‘-‘ . $easter);
$easterSec = date(‘m-d’, strtotime(‘+1 day’, $date));
$cc = date(‘m-d’, strtotime(‘+60 days’, $date));
$hol[8] = $easter;
$hol[9] = $easterSec;
$hol[10] = $cc;
}
$weekDay=date(‘w’,$date1);
if (!($weekDay==0 || $weekDay==6 || in_array(date(‘m-d’,$date1),$hol)))
$count++;
$date1=strtotime(‘+1 day’,$date1);
}
$count*=$char;
return $count;
}
?>
Any help will be appreciated.