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.30, 8.0.1 - 8.0.23, 8.1.0 - 8.1.10, 8.2rc1
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:
18.69 ms | 409 KiB | 5 Q