3v4l.org

run code in 300+ PHP versions simultaneously
<?php $no = 0; $start = new DateTime('2022-09-01'); $end = new DateTime('2022-09-19'); $interval = DateInterval::createFromDateString('1 day'); $period = new DatePeriod($start, $interval, $end); foreach ($period as $dt) { print_r($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
DateTime Object ( [date] => 2022-09-01 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2022-09-02 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2022-09-03 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2022-09-04 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2022-09-05 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2022-09-06 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2022-09-07 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2022-09-08 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2022-09-09 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2022-09-10 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2022-09-11 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2022-09-12 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2022-09-13 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2022-09-14 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2022-09-15 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2022-09-16 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2022-09-17 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) DateTime Object ( [date] => 2022-09-18 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) 3

preferences:
19.37 ms | 419 KiB | 5 Q