5 Replies Latest reply: Nov 5, 2016 11:36 PM by Ashok Vaddireddy RSS

    How to count the dif between two dates?

    Brianna Knoppow



      I need to find out the difference between two dates.


      Reference #             Open Date                   Close Date

      1                         31-May-16                         21-Jun-16

      2                          1-Jul-16                                 -

      3                         31 May-16                         15-Jun-16





      The format looks like: 30-Sep-16 for the dates. Then I would like to show in a chart format the amount of time the Reference #s were open. i have not worked with dates yet in Qlik.

        • Re: How to count the dif between two dates?
          Allu Allu

          Are you looking for diffference in days or hours ?



          Interval ( Open Date -Close Date ,'dd')







          syntax: networkdays (start_date, end_date [, holiday])


          networkdays (Open Date, Close Date )

            • Re: How to count the dif between two dates?
              Brianna Knoppow

              Hi Allu,


              I am seeking the difference in days.

                • Re: How to count the dif between two dates?
                  Stefan Wühl

                  First, you need to interpret the input record values for your two date fields as dates, either by setting the default date format correctly or using the date#() interpretation function:


                  Get the Dates Right

                  Why don’t my dates work?


                  Now your field values are duals, still showing the formatted date as text representation, but holding also a number you can use in dat calculations, e.g. for calculating the date difference, just subtract two date values.


                  Example script:


                  Set DateFormat = 'DD-MMM-YY';

                  SET MonthNames='Jan;Feb;Mar;Apr;May;Jun;Jul;Aug;Sep;Oct;Nov;Dec';


                  LOAD *,

                    [Close Date]-[Open Date] as Duration

                  INLINE [                                                                            // INLINE table only used for demonstration

                  Reference #,        Open Date,                  Close Date

                  1,                        31-May-16,                  21-Jun-16

                  2,                          1-Jul-16,                            -

                  3,                        31-May-16,                  15-Jun-16


              • Re: How to count the dif between two dates?
                Marco Wedel



                another solution might be:





                LOAD *,
                    [Close Date]-[Open Date] as DaysOpen;
                LOAD [Reference #],
                    Date(Date#([Open Date],'DD-MMM-YY'))                as [Open Date],
                    Date(Alt(Date#([Close Date],'DD-MMM-YY'), Today())) as [Close Date]
                INLINE [
                    Reference #, Open Date, Close Date
                    1,          31-May-16, 21-Jun-16
                    2,            1-Jul-16, -
                    3,          31-May-16, 15-Jun-16


                hope this helps





                • Re: How to count the dif between two dates?
                  Ashok Vaddireddy

                  Hi Brianna,


                  Its just simple as


                  Num(Close Date) -  Num(Open Date) as Diff