Search code examples
laravelphp-carbon

How to get diff in days include last day of given date in laravel?


here is my code for getting diff in days

 $endDate = Carbon::parse($input['to_date']);
 $startDate = Carbon::parse($input['from_date']);
 $rentDays = $startDate->diffInDays($endDate);

eg. fromdate= '29-11-2021' and to date ='03-12-2021' it returns 4 days. i want to get 5 days


Solution

  • You can use this

    $rentDays = $startDate->diffInDays($endDate) + 1;
    

    or

    $rentDays = $startDate->diffInDays($endDate->addDays(1));