Eureka Moment Wiki

One eureka moment at the time

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)

Discussion

Enter your comment:
B B H H L
 
database/mssql/sum_datetime_diff.txt · Last modified: 2019/10/31 09:04 (external edit)