How can I calculate the number of Saturdays and Sundays between two dates in php?
Is there any inbuilt function for that purpose?
diff($d1);
$number_of_days = $interval->format("%d");
$number_of_weekends = $number_of_days / 7;
$remainder = $number_of_days % 7;
if ($remainder >=2 && $d1->format("D") == "Sat")
$number_of_weekends++;
elseif ($d1->format("w") + $remainder >= 8)
$number_of_weekends++;
I may have missed by one in the last condition, be sure to check it with different starting dates. (Feel free to edit this answer if you spot an error).