3v4l.org

run code in 300+ PHP versions simultaneously
<?php $date_from1 = new DateTime('1-9-2016'); $date_from=$date_from1->format('Y-m-d'); $date_to1 = new DateTime('30-9-2016'); $date_to=$date_to1->format('Y-m-d'); $diff1=$date_from1->diff($date_to1); $diff2= $diff1->format('%R %a days'); $interval = new DateInterval('P1D'); preg_match_all('!\d+!', $diff2, $matches); //use that to get only number from diff2 for($i=0; $i <= $matches[0][0]; $i++) //$matches return diff2 only number of days { $this_date= $i? $date_from1->add($interval): $date_from1; echo $this_date->format('Y-m-d') . "\r\n"; }
Output for 5.6.0 - 5.6.25, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
2016-09-01 2016-09-02 2016-09-03 2016-09-04 2016-09-05 2016-09-06 2016-09-07 2016-09-08 2016-09-09 2016-09-10 2016-09-11 2016-09-12 2016-09-13 2016-09-14 2016-09-15 2016-09-16 2016-09-17 2016-09-18 2016-09-19 2016-09-20 2016-09-21 2016-09-22 2016-09-23 2016-09-24 2016-09-25 2016-09-26 2016-09-27 2016-09-28 2016-09-29 2016-09-30

preferences:
110.72 ms | 409 KiB | 5 Q