如何获得天数差异,包括 laravel 中给定日期的最后一天?

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

这是我在几天内获取差异的代码

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

例如。 fromdate= '29-11-2021' 到 date ='03-12-2021' returns 4 天。我想要5天

你可以用这个

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

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