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); print_r($period); foreach ($period as $dt) { if ($dt->format('N') == 7) { $no++; } } echo $no;
Output for 8.2rc1
DatePeriod Object ( [start] => DateTime Object ( [date] => 2022-09-01 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) [current] => [end] => DateTime Object ( [date] => 2022-09-19 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) [interval] => DateInterval Object ( [y] => 0 [m] => 0 [d] => 1 [h] => 0 [i] => 0 [s] => 0 [f] => 0 [invert] => 0 [days] => [from_string] => ) [recurrences] => 1 [include_start_date] => 1 [include_end_date] => ) 3
Output for 7.4.0 - 7.4.30, 8.0.1 - 8.0.23, 8.1.0 - 8.1.10
DatePeriod Object ( [start] => DateTime Object ( [date] => 2022-09-01 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) [current] => [end] => DateTime Object ( [date] => 2022-09-19 00:00:00.000000 [timezone_type] => 3 [timezone] => Europe/Amsterdam ) [interval] => DateInterval Object ( [y] => 0 [m] => 0 [d] => 1 [h] => 0 [i] => 0 [s] => 0 [f] => 0 [weekday] => 0 [weekday_behavior] => 0 [first_last_day_of] => 0 [invert] => 0 [days] => [special_type] => 0 [special_amount] => 0 [have_weekday_relative] => 0 [have_special_relative] => 0 ) [recurrences] => 1 [include_start_date] => 1 ) 3

preferences:
18.46 ms | 414 KiB | 5 Q