Get sum of duration


in VB.NET i want to create a sql statement for sql-server that gives me the duration.

Like this:
    FromDateTime= 07/04/2006 15:00
    ToDateTime= 07/04/2006 15:10
    FromDateTime= 07/04/2006 15:20
    ToDateTime= 07/04/2006 15:25
    FromDateTime= 07/04/2006 15:30
    ToDateTime= 07/04/2006 15:50

When i do this "SELECT <what to place here?> FROM Table WHERE Filterfield=1"
i should get something like
30minutes or even in seconds or milliseconds, i don't care about that, i just want this data out like that.
seconds, milliseconds,minutes,... are easy to convert to anything else.
Joachim CarreinSr. Software DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hello joachimcarrein,

you could use

SELECT (ToDateTime - FromDateTime) AS Duration FROM Table WHERE Filterfield=1

hope this helps a bit

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Joachim CarreinSr. Software DeveloperAuthor Commented:
this gives me also datetimes, i have already tried this before

i just got to this, this seems to work fine:
SELECT     DATEDIFF(s, FromDateTime, ToDateTime) AS Total
FROM         table
WHERE      Filterfield=1
Joachim CarreinSr. Software DeveloperAuthor Commented:
Thanks for searching anyway, i give you the credit, but only C
well you could've left this open for a while there are others looking at it, and i was preparing a table to test with
i used this on a table here with fields that contain a datefield filled with a format

yyyy/mm/dd hh:mm:ss

select CONVERT(varchar(8), (MAX(tiqdate) - MIN(tiqdate)), 14) AS Duration from myTable
where id = 23991
and mydate between '20060410 09:15:00' and '20060410 09:35:00'

returning the hh:mm:ss part

00:17:00 which are 17 minutes between the 2 in the select
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.