Hey All,
This is slowly driving me nuts, so bare with me..
I have two times, one is a string in this format: HH:MM:SS and the other is date('H:i:s')
I need to know the difference in minutes and then say if the difference is over 60minutes then I will delete a row from a database.
I have the following bodged together:
$date = '2008-10-22 00:55:34'; //for example sake
function distanceOfTimeInWords($fromTime, $toTime) {
$distanceInSeconds = round($fromTime - $toTime);
$distanceInMinutes = round($distanceInSeconds / 60);
return $distanceInMinutes;
}
$startHour = substr($date, 11, 2);
$startMin = substr($date, 14, 2);
$startTime = strtotime($startHour.':'.$startMin.':00');
$thisTime = strtotime(date('H:i:s'));
$timeleft = 60 - distanceOfTimeInWords($startTime, $thisTime);
if ($timeleft < 0) {
mysql_query("DELETE FROM cart WHERE id = '$CartID'");
}
I'm getting results where the $timeleft value will count down, but when it gets to 0 it will start counting up again... or it may be the other way round (sorry, I'm so tired).
Has anyone got a better way of doing this? or a solution to the above issue?
Thanks in advance for any replies.