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.
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.
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;
}
Use CarbonPeriod
to get day beetween two date
$period = \Carbon\CarbonPeriod::create(request('start'), request('end'));
foreach ($period as $key => $date) {
dump($date->format('Y-m-d'));
}
With carbon period you can get both start and end date.