Ahmad Badpey
Ahmad Badpey

Reputation: 6622

Difference between now and future date as x day , y hours , z minutes via php Carbon

I'm using laravel 5.5 and Carbon DateTime Library and have a future date and want to display difference between that time and Now.

But note that I want to display differences as this format :

x day , y hours , z minutes

that shows how many days, hours and minutes is left to that future date

Upvotes: 1

Views: 809

Answers (2)

user6679664
user6679664

Reputation:

You can read the documentation here regarding everything with difference between dates:

PHP Date difference

Upvotes: 1

Alexey Mezenin
Alexey Mezenin

Reputation: 163968

Use the diff() method and d, h and i properties like this:

$diff = $date->diff(now());

{{ $diff->d . ' days, ' . $diff->h . ' hours, ' . $diff->i . ' minutes' }}

http://carbon.nesbot.com/docs/

Upvotes: 2

Related Questions