Jump to content

time diffrence calc problem


GD77

Recommended Posts

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

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
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.