Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Format and sum of datetime.

Author  Topic 

TazMania
Yak Posting Veteran

63 Posts

Posted - 2004-12-07 : 08:09:42
Hi

I'm looking for a way to calculate the sum of a datetime column, i've searched through the forum, but nothing turned up which i could modify a little to meet my needs...

my table dif looks a little like this.

id ident.
usrid varchar
usage datetime

id usrid usage
1 28780116 01:34:00
2 28780116 00:06:02
3 28780805 00:00:10
4 28780116 00:00:15

I would then like to return a result for 28780116. and in the format 00:00:00, the result for 28780116 should look like this 01:40:17 Is this possible ?

select * from table sum(???) where usrid='28780116'

Any help would be much appreciated.

Best regards
Taz

robvolk
Most Valuable Yak

15732 Posts

Posted - 2004-12-07 : 08:14:25
If all of your date values are time only, this should work:

SELECT DateAdd(s, Sum(DateDiff(s, 0, usage)), 0) AS TotalTime FROM myTable WHERE usrid='28780116'

You'll get a date portion as well, and if the total exceeds 24 hours you'll need to work on it a little more to get the right display.
Go to Top of Page

TazMania
Yak Posting Veteran

63 Posts

Posted - 2004-12-07 : 08:42:21
Hi robvolk.

Thank you.. it works like a charm

Best regards
Taz
Go to Top of Page
   

- Advertisement -