Created
October 30, 2017 19:32
-
-
Save jonatanrdsantos/9d57f18e4df864c9fd9583ed0d114d8c to your computer and use it in GitHub Desktop.
Calculo de dias úteis em php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getWorkingDays($startDate, $endDate) { | |
$begin = strtotime($startDate); | |
$end = strtotime($endDate); | |
if ($begin > $end) { | |
return 0; | |
} | |
else { | |
$holidays = array('01/01', '03/04', '21/04', '01/05', '07/09', '12/10', '02/11', '15/11', '25/12'); | |
$weekends = 0; | |
$no_days = 0; | |
$holidayCount = 0; | |
while ($begin <= $end) { | |
$no_days++; // no of days in the given interval | |
if (in_array(date("d/m", $begin), $holidays)) { | |
$holidayCount++; | |
} | |
$what_day = date("N", $begin); | |
if ($what_day > 5) { // 6 and 7 are weekend days | |
$weekends++; | |
}; | |
$begin += 86400; // +1 day | |
}; | |
$working_days = $no_days - $weekends - $holidayCount; | |
return $working_days; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment