Time difference
Moderator: General Moderators
Time difference
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....
You might want to have a look at strtotime();
A very rough example, someone may come up with a cleaner solution.
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);That's a whole lot of work for what one mysql function can do
TIMEDIFF()