User Tools

Site Tools


database:mssql:sum_datetime_diff

Sum datetime difference in MSSQL

Get the SUM of seconds:

SET @Seconds = SELECT SUM(DATEDIFF(SECOND, [START_TIME], [END_TIME]))

Turn 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)
database/mssql/sum_datetime_diff.txt · Last modified: 2017/08/10 10:59 (external edit)