2 Replies Latest reply: Jul 19, 2016 1:04 PM by Henric Cronström RSS

    Difference between two dates (in hours)

      I have a date column, let's say Order_Date, which comes from the load of an excel sheet through one of my scripts.This column is a date and its format is DD/MM/YYYY.


      What I would like to do is calculate the difference between the maximum and minimum dates in hours. So I have done the following:


      (Interval(Max(Order_Date)-Min(Order_Date),'DD') * 24


      Is that correct?

        • Re: Difference between two dates (in hours)
          Sunny Talwar

          This should work

          Interval(Max(Order_Date) - Min(Order_Date),'DD') * 24


          or you can try this:

          Interval(Max(Order_Date) - Min(Order_Date), 'h')

          • Re: Difference between two dates (in hours)
            Henric Cronström

            The Interval() function is just a formatting function, so you don't need it in Sunny's first formula. (Doesn't do anything bad, either...). So if you use

            (Max(Order_Date) - Min(Order_Date)) * 24

            you will get a number corresponding to the number of hours.


            And if you use

            Interval(Max(Order_Date) - Min(Order_Date), 'h')

            you will get the number of days, but formatted as hours. E.g. if the difference between min and max is exactly 10 days, the underlying value will be 10, but its textual representation will be '240'.