I'm trying to figure out how many specific days of the week there are between two time periods.
As I said in this question , I'm using this script, adapted with help , to get the weekdays, taking Saturdays, Sundays and national holidays:
$beginday = isset($_POST["Tinsem3"]) ? $_POST["Tinsem3"] : false;
$lastday = isset($_POST["Tdesl"]) ? $_POST["Tdesl"] : false;
$nr_work_days = getWorkingDays($beginday, $lastday);
function getWorkingDays($startDate, $endDate) {
$begin = strtotime($startDate);
$end = strtotime($endDate);
if ($begin > $end) {
echo "startdate is in the future! <br />";
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;
}
}
But I wanted to pick up how many specific days of the week there are between these two periods. I have very basic knowledge of PHP, so a good explanation would also be welcome.
I know that just getting the specific days is just taking the difference and counting how many days of the week there are between the dates (you do not need this whole script). But is there a specific function for this?
Something like:
function getWednesDays($startDate, $endDate) {
$begin = strtotime($startDate);
$end = strtotime($endDate);
$totaldequartasfeiras = XXX
I put the script together because I also need national holidays not to be included, so it would be nice if I could "enjoy" this part.