I have a query such that the query\'s result is:
SELECT CONVERT(VARCHAR(8),(MAX(END_TIME)-MIN(START_TIME)),108) as DURATION WHERE ... GROUP BY TITLE
<
Convert minutes into seconds
SUM()
the seconds
Convert back to minutes
The following will give you the SUM of seconds:
SET @Seconds = SELECT SUM(DATEDIFF(SECOND, [START_TIME], [END_TIME]))
The following then turns that into a datetime
object:
select convert(varchar(8), dateadd(second, @Seconds, 0), 108)
Or as 1 query:
SELECT convert(varchar(8), dateadd(second, SUM(DATEDIFF(SECOND, [START_TIME], [END_TIME])), 0), 108)
You cannot sum times. What you should do instead is use the DateDiff function with your start and end time using the seconds parameter. This will return an integer data type which you can SUM on. When you're done, convert it to a DateTime to format it like hours:minutes:seconds.