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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I add the values of a field that contains a duration?

Status
Not open for further replies.

Henk1

Programmer
Oct 26, 2001
46
ZA
Good day,

How would I add nVarChar fields with values "00:00:02", "00:00:05", etc, etc, simulating the duration of a telephone call together?

I tried using SUM(field) but it cannot add up a nVarChar field.

I also tried using SUM(CONVERT(datetime, field)) but that does not work either, saying that you cannot sum up a datetime field.

Which data type should I use, or is there another way?

Thanks in advance for any help.
 
Sorry about my post. I got the answer. What I did was write this function :

Code:
CREATE FUNCTION fnSeconds (@CallTime nVARCHAR(50))
RETURNS DECIMAL(18,2) AS  
BEGIN 
DECLARE @CallSeconds DECIMAL(18,2)
DECLARE @CallMinutes DECIMAL(18,2)
DECLARE @CallHours DECIMAL(18,2)
SELECT  @CallSeconds = DATEPART (SECOND, @CallTime)
SELECT  @CallMinutes = DATEPART (MINUTE, @CallTime)
SELECT  @CallHours = DATEPART (HOUR, @CallTime)
DECLARE @ReturnDuration DECIMAL(18,2)
SELECT  @ReturnDuration = @CallSeconds + (@CallMinutes * 60) + (@CallHours * 60 * 60)
RETURN  @ReturnDuration
END

And then just called the function with my value.

Thanks anyways.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top