...

View Full Version : Compare time php



Erindesign
02-27-2010, 07:20 PM
is there any standard way to compare time?

I have a script that loads a few events, by time. If the script is kept open for a bit on a browser, the events are still loaded, but their "time" might have expired. so in order to alter these events i need to compare their times.

ex 1:
$event time is H:m (14:55).
$compare=date('H:m'); (suppose now it is 15:00)

ex 2:
$event time is H:m (14:55).
$compare=date('H:m'); (suppose now it is 14:30)

How would I be able to see if $event has passed, and get the difference in the same format?
in example 1, $event has passed.
in example 2, there are 25 minutes still. difference is 00:25.

F00Baron
02-27-2010, 11:16 PM
Something like this?

$current = date('H:m');
$event_minutes = substr($event,0,2) + (60 * substr($event,3,2));
$current_minutes = substr($current,0,2) + (60 * substr($current,3,2));

$minutes_left = max(0,$event_minutes - $current_minutes);
$time_left = ($minutes_left / 60) . ':' . $minutes_left % 60;



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum