I wrote a simple program to count the number of Sunday days between two dates. If there are large gaps between dates, the script takes a very long time to execute. Can this be somehow optimized?
$sunDay = 0;
$start = DateTime::createFromFormat('m.d.X', "02.12.2023");
$end = DateTime::createFromFormat('m.d.X', "04.12.292277026596");
for ($i = $start; $i <= $end; $i = $i->modify('+1 day')) {
if ($i->format('N') > 6) $sunDay++;
}