Page 1 of 1
Time difference
Posted: Wed Aug 09, 2006 9:30 am
by nhan
i have two time values that comes from the database in this format (10:17:45 PM) how can i find its difference...? i have searched the forums and it gave me 2838 results... can someone provide me the link or the solution maybe.. thanks in advance....
Posted: Wed Aug 09, 2006 9:52 am
by bmcewan
You might want to have a look at
strtotime();
A very rough example, someone may come up with a cleaner solution.
Code: Select all
$time1 = strtotime($_POST['time1']);
$time2 = strtotime($_POST['time2']);
if ($time1 > $time2) { // avoid having a negative timestamp
$time_diff = $time1 - $time2;
} else {
$time_diff = $time2 - $time1;
}
$time_diff_text = strftime("%H:%M:%S, $time_diff);
Posted: Wed Aug 09, 2006 10:29 am
by nhan
thanks so much, i have done the script it gave me an idea, though the answer is somewhat confusing, time1=10:00:00 PM and Time2=11:45:20:PM, the answer gave me 9:45:20 PM which is confusing indeed.. anyways.. ill just manipulate the script.. thank you so much!
Posted: Wed Aug 09, 2006 11:04 am
by hawleyjr
That's a whole lot of work for what one mysql function can do
TIMEDIFF()