Home > Back-end >  Exclude "weeks" from Carbon human readable date difference
Exclude "weeks" from Carbon human readable date difference

Time:08-27

I use Carbon with Laravel for date manipulations and display. I can get the difference between a given date and current time using

$date->diffForHumans()

But my problem is I want everything less than a month to be shown as days and exclude showing "weeks". For example 29 days is shown as 4 weeks 1 day by Carbon, but I want it to be shown as 29 days. It is fine for me if it shows 30 days as 1 month but I do not want "weeks".

Is there a way to do it? Any help appreciated.

CodePudding user response:

https://github.com/briannesbitt/Carbon/issues/2465

$date->diffForHumans([
    'parts'       => 4,
    'skip'        => ['week'],
    'minimumUnit' => 'minute',
]);
  • Related