Answered Sum Time column

  • Thursday, February 07, 2013 12:59 PM
     
     

    hi

    I want to sum time part in datetime column.

    ID   SK_ID   DateTime 

    1     2      2012-12-12 12:50:59.000
    1     2      2012-12-12 12:50:44.000
    1     2      2012-12-12 12:49:52.000

    Sum of

    12:50:59.000

    12:50:44.000

    49:52.000

    pls help me on it


    /R.

All Replies

  • Thursday, February 07, 2013 1:08 PM
     
     Answered

    Convert minutes into seconds then back to miuntes

    please refer

    http://stackoverflow.com/questions/7793531/how-can-i-get-the-sum-of-multiple-datetime-values

    please mark as answer if helpful

  • Thursday, February 07, 2013 1:09 PM
    Moderator
     
     Proposed Answer Has Code

    Try

    select sum(datepart(hour,[DateTime]) * 3600 +

    datepart(minute,[DateTime]) * 60 + datepart(second, [DateTime])) as [Duration in Seconds]

    from myTable


    Once you got duration in seconds you can change it back to total hours, total minutes and seconds by applying the same formula in reverse.


    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog


  • Thursday, February 07, 2013 1:10 PM
     
     

    Its one column value ....


    /R.