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($dt); if ($dt->format('N') == 7) { $no++; } } echo $no;
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
Fatal error: Uncaught Error: Object of class DateTime could not be converted to string in /in/LBQ1s:10 Stack trace: #0 {main} thrown in /in/LBQ1s on line 10
Process exited with code 255.

preferences:
120.07 ms | 402 KiB | 117 Q