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"; }

preferences:
24.91 ms | 404 KiB | 5 Q