B L Praveen
B L Praveen

Reputation: 1990

Laravel Carbon get passed years relative to current time

I need to show the passed years like 5.6 years with a given date $model->created_at

What I tried so far is

$dt     = Carbon::now();
echo $dt->diffForHumans($model->created_at); 1 month ago

how to show date only like 5.6 years

Upvotes: 0

Views: 390

Answers (1)

OMR
OMR

Reputation: 12188

you can use Carbon::floatDiffInRealYears to get exactly the different,

and Carbon::diffInYears to get the rounded result of the previous method

$dt     = Carbon::now();
echo $dt->floatDiffInRealYears($model->created_at); 

Upvotes: 2

Related Questions