3v4l.org

run code in 300+ PHP versions simultaneously
<?php $no = 0; $start = new DateTime('2022-09-01'); $end = new DateTime('2022-09-18'); $interval = DateInterval::createFromDateString('1 day'); $period = new DatePeriod($start, $interval, $end); foreach ($period as $dt) { if ($dt->format('N') == 7) { $no++; } } echo $no;
Output for 7.4.0 - 7.4.30, 8.0.1 - 8.0.23, 8.1.0 - 8.1.10, 8.2rc1
2

preferences:
23.71 ms | 409 KiB | 5 Q