Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add time durations

Status
Not open for further replies.

Delphin

Programmer
Nov 27, 2001
134
US
I am trying to write a query that will add the time from several different activities.

Ex Activity1: Time 1:00:34
Activity2: Time 0:03:45
Activity3: Time 0:05:26

I need the total time by adding these together. Not sure how to accomplish this from SQL Server


Billy Ballard

For in the past, Lies the future.
 
here is a start:
[/code]
create table #t ( hm varchar(5))
insert #t values('8:30')
insert #t values('5:45')
insert #t values('12:12')
insert #t values('7:20')


select convert(varchar, sum(datediff(ss, '1900-01-01 00:00', convert(datetime, hm)))/3600) +
':' +
convert(varchar, (sum(datediff(ss, '1900-01-01 00:00', convert(datetime, hm)))%3600)/60)

from #t
[/code]

[bandito] [blue]DBomrrsm[/blue] [bandito]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top