>I am trying to get an accurate (nearest 15 minutes would be
>fine) difference between two times that I have in my database. They are
>both of type time, and are in the format 00:00:00.
>For example, if I want the difference between 09:20:00 and 10:43:00, I
>would like it to give me 01:23:00 as the answer, but all I have been able
>to get it to do is give me one. It is rounding to the nearest hour.
>I found this query which seems like it would work, but gives me a NULL
>SELECT DATE_SUB('11:48:02', INTERVAL '10:37:37' HOUR_SECOND);
For two times t1 and t2, compute the difference in seconds like this:
SELECT TIME_TO_SEC(t2) - TIME_TO_SEC(t1)
If you want the result as a time value, pass it to SEC_TO_TIME():
SELECT SEC_TO_TIME(TIME_TO_SEC(t2) - TIME_TO_SEC(t1))
>I am trying to do all of this from PHP, so if you happen to know of a way
>to make it do the subtraction in PHP without losing all accuracy, please
>let me know.
>Thanks for any help you can offer.