Showing posts with label weekends. Show all posts
Showing posts with label weekends. Show all posts

Friday, 11 July 2014

How to calculate no of working days in php?

function getWorkingDays($startDate, $endDate){
   $begin=strtotime($startDate);
   $end=strtotime($endDate);
   if($begin>$end){
     echo "tartdate is in the future! 
"; return 0; }else{ $no_days=0; $weekends=0; while($begin<=$end){ $no_days++; // no of days in the given interval $what_day=date("N",$begin); if($what_day>6) { // 6 and 7 are weekend days $weekends++; }; $begin+=86400; // +1 day }; $working_days=$no_days-$weekends; return $working_days; } }