Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Breezy
Creator II
Creator II

How to count the dif between two dates?

Hello,

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.

5 Replies
Anonymous
Not applicable

Are you looking for diffference in days or hours ?

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

or

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



networkdays (Open Date, Close Date )

Breezy
Creator II
Creator II
Author

Hi Allu,

I am seeking the difference in days.

swuehl
MVP
MVP

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

];

MarcoWedel

Hi

another solution might be:

QlikCommunity_Thread_238775_Pic1.JPG

QlikCommunity_Thread_238775_Pic2.JPG

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

regards

Marco

Not applicable

Hi Brianna,

Its just simple as

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