I'm using a script that I found in this question of the SOen, and to count the working days disregarding Saturday and Sunday (can only do with Sunday tbm, changing $what_day > 5
to $what_day > 6
for example) it works right, but I wanted to include the calendar official holiday of Brazil.
This is the script that is working (already taking the data from my form):
<?php
//get current month for example
$beginday = ($_POST ["Tdesl"]);
$lastday = ($_POST ["Tinsem3"]);
$nr_work_days = getWorkingDays($beginday, $lastday);
echo $nr_work_days;
function getWorkingDays($startDate, $endDate)
{
$begin = strtotime($startDate);
$end = strtotime($endDate);
if ($begin > $end) {
echo "startdate is in the future! <br />";
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 > 5) { // 6 and 7 are weekend days
$weekends++;
};
$begin += 86400; // +1 day
};
$working_days = $no_days - $weekends;
return $working_days;
}
}
HTML:
<form method="post" id="Cform" name="Tform" action="diasuteis2.php">
<label for="Cinsem">Data inicial:</label>
<input type="date" name="Tinsem3" id="Cinsem" size="6">
<label for="Cdesl22">Data final:</label>
<input type="date" name="Tdesl" id="Cdesl22" size="6"><br><br>
<p align="center">
<input type="submit" id="enviar"></p>
</form>
An example of correct output for:
echo $beginday;
echo "<br><br>";
echo $lastday;
echo "<br><br>";
echo $nr_work_days;
It is:
2014-12-10
2014-12-15
4
(He considered day 10, and deleted days 13 and 14 correctly)
Is it possible, or feasible, to include the holidays in this code? If someone can make an example (of course you do not need to include all the holidays, just show me how I can do this) thank you in advance.