How to extract hours, minutes and seconds out of a difference between 2 dates?

  • Hello,

    I'm stuck with this one. I've 2 date field (start date and end date) I want to get the difference between those 2 in this format:

    Hours:Min:seconds

    I tried the DATEDIFF with the DATEPART without any success.

    Has someone any idea?

    Thanks in advance.

    Eric K.

  • This example doesn't really make sense, but I couldn't think of a better one right now

    USE NORTHWIND

    GO

    SELECT REPLACE(STR(DATEDIFF(ss,orderdate,shippeddate) / 3600,4),' ',0)+

     ':' +

     REPLACE(STR((DATEDIFF(ss,orderdate,shippeddate) / 60)% 60,2),' ',0) +

     ':' +

     REPLACE(STR(DATEDIFF(ss,orderdate,shippeddate) % 60,2),' ',0)

    FROM

     Orders

    You might have to tweak this one

    SELECT REPLACE(STR(DATEDIFF(ss,orderdate,shippeddate) / 3600,4),' ',0)+

    according to your needs.

    HTH

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • Thanks Frank, it works fine.

    BR

    Eric

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply