3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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") . PHP_EOL; }
based on 83Yk8
Output for 5.3.18 - 5.4.45, 5.6.28, 7.0.20 - 7.2.0
2012-01 2012-07 2013-01 2013-07 2014-01 2014-07 2015-01 2015-07
Output for 5.5.24 - 5.6.21, 7.0.0 - 7.0.6
2012-01 2012-07 2013-01 2013-07 2014-01 2014-07 2015-01 2015-07 2016-01