Roman Kutenko
Roman Kutenko

Reputation: 27

How to calculate duration between to time using php?

I want to calculate time duration between 23:10 and 01:30. I need to get 02:20, but I got about 22 hours. Now I use Carbon library e.g.

Carbon::parse($request->departure_time)->diffInMinutes(Carbon::parse($request->arrival_time), false);

Upvotes: 0

Views: 78

Answers (1)

Mike Foxtech
Mike Foxtech

Reputation: 1651

you need to add dates because php thinks it's same day

for example

$startTime = "2011-01-03 23:10";
$endTime = "2011-01-04 01:30";

Upvotes: 1

Related Questions