Get sum of duration

Posted on 2006-04-11
Last Modified: 2012-08-14

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.
Question by:joachimcarrein
    LVL 44

    Accepted Solution

    Hello joachimcarrein,

    you could use

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

    hope this helps a bit
    LVL 4

    Author Comment

    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
    LVL 4

    Author Comment

    Thanks for searching anyway, i give you the credit, but only C
    LVL 44

    Expert Comment

    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
    LVL 44

    Expert Comment

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Suggested Solutions

    This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
    Article by: Kraeven
    Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now