$createdTime = Carbon::parse($specialist->created_at)
->diff(Carbon::now())
->format('%y yr, %m mo and %d days');
This returns 0 yr, 0 mo and 8 days
. I want to return only 8 days
.
Or if 1 yr, 0 mo and 8 days
, return 1 yr and 8 days
There is a better solution rather than using
diffForHumans()
and removeago
withstr_replace($time->diffForHumans(), ' ago')
.I recommand using the CarbonInterval like this :
Since
diff()
returns aDateInterval
instance you could run conditional checks to get your expected result.