convert hours into decimal

  • i have a formula that calculates the difference between two dates and tells me the hours but instead of giving round in hours, i need hours to be displayed in decimal format. Can someone direct me to the right formula to use?

     

     

    Delivered = l.ArriveDateTime ,

    Weighed = t.TareWeighedDateTime ,

    Processed = l.ProcessedDateTime ,

    'Wait Time' = DATEDIFF(SECOND, l.ArriveDateTime, l.ProcessedDateTime)/3600,

  • Are you looking for:

     Select datediff(minute, '2021-07-01 01:15:00', '2021-07-01 01:30:00') / 60.0
    Select datediff(second, '2021-07-01 01:15:00', '2021-07-01 01:30:00') / 60.0 / 60.0

     

     

    Jeffrey Williams
    Problems are opportunities brilliantly disguised as insurmountable obstacles.

    How to post questions to get better answers faster
    Managing Transaction Logs

  • If you introduce a decimal type value into the equation, you turn the results from int to decimal. Note the slight difference between the two function calls - one uses 3600 and the other uses 3600.0. Using 3600.0 turns the output to a decimal.

    DECLARE @ArriveDateTime datetime = '2021-07-27 09:22:37',
    @ProcessedDateTime datetime = '2021-07-27 12:09:14';
    SELECT DATEDIFF(SECOND, @ArriveDateTime, @ProcessedDateTime)/3600 AS [Int_Version],
    DATEDIFF(SECOND, @ArriveDateTime, @ProcessedDateTime)/3600.0 AS [Decimal_Version];

    Int_Version Decimal_Version
    ----------- ---------------------------------------
    2 2.776944

    (1 row affected)

    Eddie Wuerch
    MCM: SQL

  • Thank You

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

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