Reputation: 9055
I try to get the difference between 2 dates, between date now() and a given date in Laravel app with Carbon. I do the following in my blade
\Carbon\Carbon::parse(Auth::user()->properties->first()->von)->diffForHumans()
but this returns only the years, so taking the following example where given date is 1st September, 2011
I get as result 6 years ago The expected would be 6 years and 3 months.
Is it possible the achive this with Carbon?
Upvotes: 3
Views: 2802
Reputation: 163758
You can use diff()
and it's properties:
$diff = auth()->user()->properties->first()->von->diff(now());
And then display it:
The difference is {{ $diff->y }} years and {{ $diff->m }} months
Alternatively, you could get a difference in months and use it:
$diffInMonths = auth()->user()->properties->first()->von->diffInMonths(now());
Upvotes: 2