Click here to Skip to main content
15,892,517 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to calculate the sum of following time fields with a sql query:

02:35
11:15
00:15

Result should be 14:05
How to do this with sql query?


What I have tried:

I don't know how to do this..........................................................
Posted
Updated 23-Aug-17 18:19pm

1 solution

Use following query

SELECT DATEADD(ms, SUM(DATEDIFF(ms, '00:00:00.000', YourFieldName)), '00:00:00.000') as time FROM YourTableName
 
Share this answer
 
Comments
Member 13375600 27-Aug-17 15:43pm    
My field name is type of "nchar(5)"

After running the solution1
I got This error:
"Conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value".

Some data in my field are as below
02:12
:
00:05
24:00
itsmypassion 28-Aug-17 0:52am    
Use Convert

SELECT DATEADD(ms, SUM(DATEDIFF(ms, '00:00:00.000', convert(datetime,YourFieldName))), '00:00:00.000') as time FROM YourTableName

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900