3v4l.org

run code in 300+ PHP versions simultaneously
<?php $start = new DateTime('2012-07-01'); $interval = new DateInterval('P7D'); $end = new DateTime('2012-07-31'); echo 'Exclude start date' . PHP_EOL; $period = new DatePeriod($start, $interval, $end, DatePeriod::EXCLUDE_START_DATE); foreach ($period as $date) { echo $date->format('Y-m-d') . PHP_EOL; } echo 'Include start date' . PHP_EOL; $period = new DatePeriod($start, $interval, $end); foreach ($period as $date) { echo $date->format('Y-m-d') . PHP_EOL; }
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.26, 8.0.0 - 8.0.13, 8.1rc1 - rc3
Exclude start date 2012-07-08 2012-07-15 2012-07-22 2012-07-29 Include start date 2012-07-01 2012-07-08 2012-07-15 2012-07-22 2012-07-29

preferences:
86.82 ms | 460 KiB | 5 Q