can nyone tell me a good way to do easy calculations with time, eg hours, and mins??
so if i start traveling at 6.30 and stop at 12, how long have i been traveling?? 5.30 hours...
if you understand what i mean please help.
do it like this:
// function for geting the time difference in minutes. function CorrectMinutes($time1, $time2) { $t2ar = explode(".", $time2); $h2 = $t2ar[0]; $m2 = $t2ar[1]; $t1ar = explode(".", $time1); $h1 = $t1ar[0]; $m1 = $t1ar[1]; $h = $h2 - $h1; $m = $m2 - $m1; $mm = ($h*60) +$m; return $mm; } // function for converting minutes back to hours function CorrectHours($Minutes) { if ($Minutes < 0) { $Min = Abs($Minutes); } else { $Min = $Minutes; } $H = Floor($Min / 60); $M = ($Min - ($H * 60)) / 100; $Hours = $H + $M; if ($Minutes < 0) { $Hours = $Hours * (-1); } $expl = explode(".", $Hours); $H=$expl[0]; if (empty($expl[1])) { $expl[1]=00; } $M=$expl[1]; if (strlen($M)<2) { $M = $M . 0; } $Hours=$H . "." . $M; return $Hours; } // run it like this $time1 = "09.30"; $time2 = "17.00"; $minutes = CorrectMinutes($time1,$time2); $hours = CorrectHours($minutes); echo "the differnce between $time1 and $time2 is:<br>"; echo "minutes = $minutes<br>"; echo "hours = $hours";
Thankyou very mush super lol