Hi all,

I'm pulling two times out of a MySQL database. The times are in the following format: HH:MM:SS (24-hour time including preleading zeros).

I want to be able to find the difference between the two times, and show it in the same format as per the examples below:

Example 1
Time1 = 08:00:00 (time is 8:00am)
Time2 = 13:40:00 (time is 1:40pm)
TimeDifference = 05:40:00 (difference of 5hours 40minutes)

Example 2
Time 1 = 22:00:00 (time is 10:00pm)
Time 2 = 04:00:00 (time is 4:00am the next morning)
TimeDifference = 06:00:00 (difference of 6hours)

"Time 1" will always be in the past and "Time 2" will always be in the future. As you can see, it's possible that "Time 2" will sometimes be an "earlier" time than "Time 1". In these cases, this will always mean that Time 2 is some time in the next day.

Between the many posts I've found here and also via BigResource, I haven't yet found a solution for this! Nor have any of my newbie efforts been any good.

If someone could show me how to do this, that would be great!


Cheers,

Chris