Firstly I copied the solution from this question, and then I made an if
statement to check if the final date $endDate
is a Sunday. If it is, I added their hour count to the total hour/count in the interval.
function quantitySundays($startDate, $endDate)
{
$start = new DateTime($startDate);
$end = new DateTime($endDate);
$days = $start->diff($end, true)->days;
$sundays = intval($days / 7) + ($start->format('N') + $days % 7 >= 7);
if($end->format('D') == 'Sun') {
return $sundays * 24 + $end->format('H');
} else {
return $sundays * 24;
}
}
The only modification is that you have to add H:i:s
to the dates that you pass as parameter in the function, like so: '2019-09-15 14:00:00'
.
Is this what you are looking for?