3v4l.org

run code in 300+ PHP versions simultaneously
<?php $lastDate = new DateTime(date("Y-m-01 12:00:00")); $lastDate->sub(new DateInterval("P1M")); $generateToThisDate = new DateTime(date("Y-m-01 12:00:00")); $generateToThisDate->add(new DateInterval("P20M")); while ($lastDate < $generateToThisDate) { $lastDate->add(new DateInterval("P1M")); echo $lastDate->format('Y-m-d') . " - " . $lastDate->format('Y-m-t') . "\n"; }
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 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.19, 8.3.0 - 8.3.7
2016-05-01 - 2016-05-31 2016-06-01 - 2016-06-30 2016-07-01 - 2016-07-31 2016-08-01 - 2016-08-31 2016-09-01 - 2016-09-30 2016-10-01 - 2016-10-31 2016-11-01 - 2016-11-30 2016-12-01 - 2016-12-31 2017-01-01 - 2017-01-31 2017-02-01 - 2017-02-28 2017-03-01 - 2017-03-31 2017-04-01 - 2017-04-30 2017-05-01 - 2017-05-31 2017-06-01 - 2017-06-30 2017-07-01 - 2017-07-31 2017-08-01 - 2017-08-31 2017-09-01 - 2017-09-30 2017-10-01 - 2017-10-31 2017-11-01 - 2017-11-30 2017-12-01 - 2017-12-31 2018-01-01 - 2018-01-31

preferences:
228.11 ms | 405 KiB | 332 Q