Get working days between two dates, with custom off day


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /**
  2.  * Get working days between two dates, with custom off day
  3.  *
  4.  * @param Date $startDate End Date
  5.  * @param Date $endDate To date
  6.  * @param Array $holidays Week Number in Single dimension array
  7.  * @return integer
  8.  */
  9.  
  10. function getWorkingDays_customOffDay($startDate, $endDate, $holidays) {
  11.  
  12. $day = 86400; // Day in seconds
  13.  
  14. $sTime = strtotime($startDate); // Start as time
  15. $eTime = strtotime($endDate); // End as time
  16. $numDays = round(($eTime - $sTime) / $day) + 1;
  17.  
  18. $days = array();
  19.  
  20. for ($d = 0; $d < $numDays; $d++) {
  21. $day_number = date('N', ($sTime + ($d * $day)));
  22. if (!in_array($day_number, $holidays)) {
  23. $days[] = date('Y-m-d N', ($sTime + ($d * $day)));
  24. }
  25. }
  26.  
  27. return count($days);
  28.  
  29. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.