Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get days and hours from diffForHumans with Carbon?

Tags:

php

php-carbon

I want to display how many days and hours to a date using Carbon, currently I got the code below.

Carbon::parse("2017-03-07 17:46:50")->diffForHumans()

It outputs:

6 days from now

I want it to output something like this:

6 days and 12 hours from now

How can I do that?

like image 922
Antonio Avatar asked Nov 09 '22 01:11

Antonio


1 Answers

You can specify the level of details like this:

Carbon::parse("2017-03-07 17:46:50")->diffForHumans(['parts' => 6]);

You can use a value from 1 to 6. (Doc)

like image 74
tompec Avatar answered Nov 14 '22 22:11

tompec