0

I have two date fields Start and End

         <input type="date" name="start>
         <input type="date" name="end>

Now i want to get number of days between the selected range and all the dates which comes in this range.

Rob
  • 14,107
  • 28
  • 46
  • 64
Muhammad Kazim
  • 592
  • 8
  • 23
  • 1
    Possible duplicate of [How to calculate the difference between two dates using PHP?](https://stackoverflow.com/questions/676824/how-to-calculate-the-difference-between-two-dates-using-php) – felipsmartins Jan 13 '18 at 22:11
  • 1
    There is so many questions regarding this question. – felipsmartins Jan 13 '18 at 22:12

1 Answers1

3

You can use Carbon's diffInDays() method:

Carbon::parse(request('start'))->diffInDays(Carbon::parse(request('end')));

To list all the dates between these two dates:

$period = new DatePeriod(Carbon::parse(request('start')), CarbonInterval::day(), Carbon::parse(request('end')));
foreach ($period as $date) {
    echo $date;
}
Alexey Mezenin
  • 148,626
  • 22
  • 267
  • 261
  • great it shows the number of days and how i get the dates which comes in this range ? – Muhammad Kazim Jan 13 '18 at 22:16
  • This does not include the start date. I want to get the count in days from start to end like date 16-25 I think return should be 10 days. But returning 9 days. should include 16 and 25 dates also. How I will do that? – Abdullah Iftikhar Nov 16 '21 at 08:12