Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

brianna_in_dc
New Contributor 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
galax_allu
Valued Contributor

Re: How to count the dif between two dates?

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 )

brianna_in_dc
New Contributor II

Re: How to count the dif between two dates?

Hi Allu,

I am seeking the difference in days.

MVP
MVP

Re: How to count the dif between two dates?

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?

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

Re: How to count the dif between two dates?

Hi Brianna,

Its just simple as

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

Community Browser