Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
kamaker
Partner - Contributor II
Partner - Contributor II

Subtracting Dates Not Working Correctly

I am trying to find the difference between two dates. My original data is in numeric form start date "20181302" and end date "20180702". These are in "YYYYMMDD" format. In the load script I have changed the dates to date format. When I subtract the two dates if they have different years then it works correctly. However, if the years are the same then only the days subtract. With my example, I get -11 when the answer should be 139. 

Here is my formula:

fabs(interval(floor(date(date#([End Date],'yyyymmdd'),'m/d/yyyy'))-floor(date(date#([Start Date],'yyyymmdd'),'m/d/yyyy')),'d'))

 

I have tried multiple other methods and still get the same answer. Please help.

 

Labels (3)
1 Solution

Accepted Solutions
marcus_sommer

The conversion-pattern from date#() isn't correct because the chars should be in upper-case and the order of months and days is wrong for your input-data. Therefore try it with:

interval(date#([End Date],'YYYYDDMM')-date#([Start Date],'YYYYDDMM'),'D')

View solution in original post

1 Reply
marcus_sommer

The conversion-pattern from date#() isn't correct because the chars should be in upper-case and the order of months and days is wrong for your input-data. Therefore try it with:

interval(date#([End Date],'YYYYDDMM')-date#([Start Date],'YYYYDDMM'),'D')