2017-12-11 9 views
2

CarbonのLaravelアプリでdate now()と指定された日付の間に2つの日付の違いを取得しようとしています。指定された日付が、私は6年前に6年と3ヶ月になると予想結果として取得1st September, 2011ですので、次の例を取っ​​て、私は私のブレードCarbon diffForHumans with months

\Carbon\Carbon::parse(Auth::user()->properties->first()->von)->diffForHumans() 

に次の操作を行いますが、これは唯一の年を返します。 Carbonでこれを実現することは可能でしょうか?

+1

私の答え[here](htt)に記されているように[CarbonInterval](http://carbon.nesbot.com/docs/#api-interval)を使うことができますps://stackoverflow.com/a/47658027/4881811)! – Maraboc

答えて

1

あなたはdiff()を使用することができ、それがプロパティです:また、あなたがヶ月で違いを取得し、それを使用することができ

The difference is {{ $diff->y }} years and {{ $diff->m }} months 

:その後、

$diff = auth()->user()->properties->first()->von->diff(now()); 

そして、それを表示する

$diffInMonths = auth()->user()->properties->first()->von->diffInMonths(now()); 
関連する問題