Reputation: 51
I'm working on hall reservation project and got stuck in calculating time difference in hours and minutes.
Scenario:
Start time = 11:00 AM.
End time = 03:30 PM.
Result = 04:30.
I have tried $diff = $start->diff($end);
but it does not work.
Upvotes: 1
Views: 2452
Reputation: 430
I would suggest you to use Carbon which is the best package (IMO) for handling dates and time in php
Upvotes: 0
Reputation: 104
You should gmdate() function.
$StartTime= '11:00 AM';
$EndTime = '03:30 PM';
$sst = strtotime($StartTime);
$eet= strtotime($EndTime);
$diff= $eet-$sst;
$timeElapsed= gmdate("h:i",$diff);
Upvotes: 2