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('last 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.8 - 5.4.45, 5.6.28, 7.0.20, 7.1.0 - 7.1.33, 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.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.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
Output for 5.5.24 - 5.5.35, 5.6.8 - 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:
216.96 ms | 402 KiB | 263 Q