3v4l.org

run code in 300+ PHP versions simultaneously
<?php $start = new DateTime('2012-01-01'); $start->modify('first day of this month'); $end = new DateTime(); $end->modify('first day of next month'); $interval = DateInterval::createFromDateString('10 month'); $period = new DatePeriod($start, $interval, $end); foreach ($period as $dt) { echo $dt->format("Y-m") . PHP_EOL; }
Output for 5.4.2 - 5.4.45, 5.6.28, 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
2012-01 2012-11 2013-09 2014-07 2015-05
Output for 5.5.24 - 5.5.35, 5.6.7 - 5.6.21, 7.0.0 - 7.0.6
2012-01 2012-11 2013-09 2014-07 2015-05 2016-03

preferences:
198.39 ms | 402 KiB | 238 Q