Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Check if a date is within a certain range

Hi everyone!

Can you please show me what I can do to validate if a certain date (e.g. my_date) is within a date range?

I saw the function InYearToDate(). However this only checks if the my_date is part of the year containing the basedate.

My problem is what if the date range that I want to use spans 2 different years?

A real life example will be a Fiscal Calendar.

For instance, from May 2013 to April 2014 is my Fiscal Calendar.  Now, I need to check if my_date falls within this Fiscal Calendar.

Thanks for all your help!

1 Solution

Accepted Solutions
Peter_Cammaert
Partner - Champion III
Partner - Champion III

Or, as a variation, create two calendar objects and attach them to two variables, for instance vStartPeriod and vEndPeriod.

Stefan's expression then becomes:

IF ((my_date >= '$(vStartPeriod)') and (my_date <= '$(vEndPeriod)'), 'YES', 'NO')

And if you want the period to be always exactly 12 months long, start from the first variable (drop the second variable and calendar object) by doing this:

IF ((my_date >= '$(vStartPeriod)') and (my_date < AddMonths('$(vStartPeriod)', 12)) 'YES', 'NO')

and so on...

View solution in original post

2 Replies
swuehl
MVP
MVP

Maybe like

if(my_date >= makedate(2013,5,1) and my_date <= makedate(2014,4,30), 'Yes','No')

for example used in a load script or expression in a chart with dimension my_date.

Peter_Cammaert
Partner - Champion III
Partner - Champion III

Or, as a variation, create two calendar objects and attach them to two variables, for instance vStartPeriod and vEndPeriod.

Stefan's expression then becomes:

IF ((my_date >= '$(vStartPeriod)') and (my_date <= '$(vEndPeriod)'), 'YES', 'NO')

And if you want the period to be always exactly 12 months long, start from the first variable (drop the second variable and calendar object) by doing this:

IF ((my_date >= '$(vStartPeriod)') and (my_date < AddMonths('$(vStartPeriod)', 12)) 'YES', 'NO')

and so on...