I have a table that contains date-time values in this format:
START
1/13/2009 7:00:00AM
END
SELECT some_grouping_column, SUM(TIMEDIFF(datecol1,datecol2)) as tot_time
FROM my_table
GROUP BY some_grouping_column;
I think you have to use this code... it works :)
SELECT
SEC_TO_TIME( SUM( TIME_TO_SEC( `time` ) ) ) AS total_time
FROM time_table;
Check out the MySQL DateDiff Function
SELECT SUM(DATEDIFF(endtime, starttime))
FROM somerecordstable
WHERE starttime > '[some date]' AND endtime <= '[some date]'
You could also try:
SELECT SUM(TIMEDIFF(endtime, starttime))
FROM somerecordstable
WHERE starttime > '[some date]' AND endtime <= '[some date]'
I haven't tested the second one, but I know the first one should work.
Try looking into UNIX_TIMESTAMP and SEC_TO_TIME.
You would sum up the differences between the timestamps, then use that value (would be in milliseconds) to get the time:
SELECT SEC_TO_TIME(time_milis / 1000)
FROM (
SELECT SUM(UNIX_TIMESTAMP(date1) - UNIX_TIMESTAMP(date2)) as time_milis
FROM table
)
Use TIMEDIFF().
SUM(TIMEDIFF(end, start))