GD77 Posted July 12, 2012 Share Posted July 12, 2012 Hello, I m using the following fuction to calculate the time difference between 2 stops...Working well till I ve noticed when one of the stops was am the second was pm I got -987 as result:/ function timeDiff($T_old, $T_new) { $timeCalc = strtotime($T_new) - strtotime($T_old); $timeCalc = round($timeCalc/60); return $timeCalc; } $res=$this->timeDiff($fetch_LA_time, date("h:i:s")); Link to comment https://forums.phpfreaks.com/topic/265559-time-diffrence-calc-problem/ Share on other sites More sharing options...
Barand Posted July 12, 2012 Share Posted July 12, 2012 If only times are used, with no date info, times are assumed to be today <?php function timeDiff($T_old, $T_new) { $timeCalc = strtotime($T_new) - strtotime($T_old); $timeCalc = round($timeCalc/60); return $timeCalc; } echo timeDiff('16:54:00', date("h:i:s")); //--> -293 echo '<br />'; echo timeDiff('2012-07-11 16:54:00', date("h:i:s")); //--> 1147 ?> Link to comment https://forums.phpfreaks.com/topic/265559-time-diffrence-calc-problem/#findComment-1361030 Share on other sites More sharing options...
GD77 Posted July 12, 2012 Author Share Posted July 12, 2012 hanks a lot, worked like a charm Link to comment https://forums.phpfreaks.com/topic/265559-time-diffrence-calc-problem/#findComment-1361037 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.