Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Return days between two dates
- *
- * @param string $startDate
- * @param string $endDate
- * @param array $holidays
- * @return integer
- */
- function getWorkingDays(string $startDate, string $endDate, array $holidays = []): int
- {
- $begin = strtotime($startDate);
- $end = strtotime($endDate);
- if ($begin > $end) {
- return 0;
- } else {
- $weekends = 0;
- $noDays = 0;
- $holidayCount = 0;
- while ($begin <= $end) {
- if (in_array(date("d/m", $begin), $holidays)) {
- $holidayCount++;
- }
- /* 6 and 7 are weekend days */
- if (date("N", $begin) > 5) {
- $weekends++;
- }
- /* +1 day */
- $begin += 86400;
- /*no of days in the given interval*/
- $noDays++;
- }
- return $noDays - $weekends - $holidayCount;
- }
- }
Add Comment
Please, Sign In to add comment