I want to check difference between two times in Laravel (the day is not needed)
Carbon::createFromTimeString($this->debut)
->diffInHours(Carbon::createFromTimeString($this->fin))
if $this->debut = '08:00:00'
and $this->fin = '02:00:00'
the expected result is 18 but I have 6
How can I get the correct difference please
2
Answers
Anyway you have to set date at least relatively for the correct calculation:
The condition should be that the time difference should always be positive. If the second parameter of Carbon::diffInHours is set to false, the result is not absolute. In this case, the intermediate result is -6. If the difference is negative, 24 hours are added.
Try them yourself.