2

I get two date from user for example :

2016-10-01
2016-11-05

now I would like to get all dates between these two dates :

2016-10-01
2016-10-02
2016-10-03
2016-10-04
...
2016-11-05

I think I must use the carbon library. but I don't know how can I do !

S.M_Emamian
  • 17,005
  • 37
  • 135
  • 254
  • http://carbon.nesbot.com/docs/ - look up the `addDay` function and use a `while` loop. – ceejayoz Nov 18 '16 at 21:24
  • possibly helpful: http://stackoverflow.com/questions/31849334/php-carbon-get-all-dates-between-date-range – castis Nov 18 '16 at 21:32

1 Answers1

3

Try this:

$from = Carbon::parse('2016-10-01');
$to = Carbon::parse('2016-11-05');

With Carbon

$dates = [];

for($d = $from; $d->lte($to); $d->addDay()) {
    $dates[] = $d->format('Y-m-d');
}

return $dates;