bluetoother Posted May 13, 2007 Share Posted May 13, 2007 i want to subtract 2 time valuesEx: 18:02 - 17:55we know the result is 7but i didnt find a way to do it on phpbecause they are time valuesregards Link to comment Share on other sites More sharing options...
MildewMan1 Posted May 13, 2007 Share Posted May 13, 2007 you could try something like $time1 = strtotime("18:02");$time2 = strtotime("17:55");$time3 = $time1 - $time2;$time4 = date('i:s', $time3); Link to comment Share on other sites More sharing options...
bluetoother Posted May 13, 2007 Author Share Posted May 13, 2007 thank got it Link to comment Share on other sites More sharing options...
MildewMan1 Posted May 13, 2007 Share Posted May 13, 2007 One other thing, if you try using $time4 = date('h:i:s', $time3); for some reason it says there are 4 hours in there somewhere, so here is alternate code I just wrote that works a little better. $time1 = strtotime('18:02:00');$time2 = strtotime('17:55:00');$seconds = $time1 - $time2;$minutes = 0;$hours = 0;while ($seconds >= 60){ $seconds = $seconds - 60; $minutes = $minutes + 1;}while ($minutes >= 60){ $minutes = $minutes - 60; $hours = $hours + 1;}if ($seconds < 10){ $seconds = "0$seconds"; //if only one digit, give it the format "ss"}if ($minutes < 10){ $minutes = "0$minutes"; //if only one digit, give it the format "mm"}if ($hours < 10){ $hours = "0$hours"; //if only one digit, give it the format "hh"}echo "$hours:$minutes:$seconds"; //will now display in "hh:mm:ss" format Link to comment Share on other sites More sharing options...
bluetoother Posted May 13, 2007 Author Share Posted May 13, 2007 if the time values are 18:02 and 17:55(mktime(18,2)-mktime(17,55)) / 60 = 7i think this one is another way Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.