how to calculate travel time using source and destination times?

*爱你&永不变心* 提交于 2019-12-13 10:29:55

问题


Departure_Time at source is 18:25 and Arrival_Time at destination is 05:20 so

 tt2.Arrival_Time -tt1.Departure_Time As Travel_Time

gives -130500 instead 10:55H how to achive this? any help will be appretiated..many thanks.!!

edit- destination time is of second day..


回答1:


I wrote a code for you that you can modify the difference of days between departure and arrival.But but but this code is only and only for a single time zone.If you have different times in different time zones that's different!

<?php
/**/
$Departure_Time='05:20';//Set Departure time
$Arrival_Time='18:30';//Set Arrival time
$dayDifference=0;//You can modify this 
/**/
$a=strtotime($Departure_Time);
$b=strtotime($Arrival_Time.' + '.($dayDifference*24).' Hours');
$interval = ($b - $a) / 60;
$traveltime=date("i:s",$interval);
echo $traveltime;
?>

And I really don't have any ideas why did I use i:s for hour and minute!

But anyway it works!

Tell me if you have any problem with the code :)



来源:https://stackoverflow.com/questions/51386237/how-to-calculate-travel-time-using-source-and-destination-times

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!