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('6 month'); $period = new DatePeriod($start, $interval, $end); foreach ($period as $dt) { echo $dt->format("Y-m-d") . 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-01 2012-07-01 2013-01-01 2013-07-01 2014-01-01 2014-07-01 2015-01-01 2015-07-01
Output for 5.5.24 - 5.5.35, 5.6.7 - 5.6.21, 7.0.0 - 7.0.6
2012-01-01 2012-07-01 2013-01-01 2013-07-01 2014-01-01 2014-07-01 2015-01-01 2015-07-01 2016-01-01

preferences:
181.66 ms | 402 KiB | 238 Q