Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
Not applicable

Difference between two Dates

Hi All,

I need to find the difference between two dates. For this i used this expression below

 

(

dayStart(timestamp(END)) - dayStart(timestamp(START)))

but how to include the Start and end date also while subtracting

For Example: 

START Date: 24-Feb-2013  and END Date: 2-Mar-2013

If i used the above expression, Result is : 6

But i need the result as 7 (24,25,26,27,28,1,2)

Any idea?

Thanks,

S.Selvakuamr

1 Solution

Accepted Solutions

Re: Difference between two Dates

Simply add 1 to the result. Or use DayStart for the start date and DayEnd for the end date and round the result: round(dayend(end)-daystart(start))


talk is cheap, supply exceeds demand
6 Replies
Not applicable

Re: Difference between two Dates

try

Interval() function

example--

Interval(EndDate - StartDate)

Not applicable

Re: Difference between two Dates

Updated code

=Num(date#('2-Mar-2013','D-MMM-YYYY'))+1 - num(date#('24-Feb-2013','D-MMM-YYYY'))


=Num(date#('End','D-MMM-YYYY'))+1 - num(date#('Start','D-MMM-YYYY'))

=date#('End','D-MMM-YYYY')+1 - date#('Start','D-MMM-YYYY')

iNTERVAL(date#('2-Mar-2013','D-MMM-YYYY') - date#('24-Feb-2013','D-MMM-YYYY'),'DD')

Employee
Employee

Re: Difference between two Dates

Make sure that you have interpreted the fields correctly using Date#() or TimeStamp#() - Not Date() and TimeStamp(). If you have done so, you can just subtract one date from another and the result will be number of days between the two.

Date#(END, 'DD-MMM-YYYY') - Date#(START, 'DD-MMM-YYYY') as Duration

HIC

Not applicable

Re: Difference between two Dates

Thanks HIC but how to include Start and End date...

Let me put this in way, count of days between  Start and end date (Including start and end date)

Selva

Re: Difference between two Dates

Simply add 1 to the result. Or use DayStart for the start date and DayEnd for the end date and round the result: round(dayend(end)-daystart(start))


talk is cheap, supply exceeds demand
Not applicable

Re: Difference between two Dates

Thanks Gysbert.. "Dayend" does the trick..

Selva

Community Browser