Difference between two date/time's on seperate days?

SELECT ( TIME_TO_SEC(end_time)-TIME_TO_SEC(start_time))
                                  / 60.00 AS minutes FROM time_track where row_id=347

For example start_time will be 2010-09-09 23:31:12
and end time will be 2010-09-10 00:09:05 then the total task time for some reason goes negative (then its replaced with a zero value since it’s unsigned)
in the db.

I need to be able to get the difference in time even when it overlaps from one day to the next w/out returning the negative value… I also used

SELECT TIMEDIFF( end_time, start_time )
FROM time_track
WHERE row_id =347

Which does the calculation correct but the field in the database is stored as a decimal for example 147.85 minutes and converted to hours/etc later and this returns HH:MM:SS format for example 02:02:22

Is there a way to convert the timediff or to get the time_to_sec query to return the correct result when the days are not the same?

Any help would be greatly appreciated!

UNIX_TIMESTAMP() corrected it instead of subtracting TIME_TO_SEC()! Just wanted to post to let people know if they were running into the same issue

Ya the columns in the database are for example: start_time will be 2010-09-09 23:31:12 and end time will be 2010-09-10 00:09:05 so they contain both the date and time which works if they are both on the same day but doesn’t work for some reason if the timestamp starts on one day and ends on another (after midnight) that is the weird thing

It does actually show the correct difference with timediff, however it’s in the wrong format I need to convert it to decimal somehow and I have seen select convert but it won’t work or I should say I guess I don’t know how to use it properly! Any help would be greatly appreciated I really need to get this fixed so our time stamp isn’t incorrect!

Thanks Again Guys,
Aaron

Do end time and start time contain the date or are they strictly times? If they are the date & time, then timediff should give you the correct variation. If it’s only time, then you’ll need to include the date as well.

SELECT TIMEDIFF(end_date + ’ ’ + end_time, start_date + ’ ’ + start_time) FROM time_track WHERE row_id = 347