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: 
Not applicable

Issue with addmonths

Hello all,

I have a slight problem with addmonths function.

set errormode = 0;

Let vActualYearAndMonth        = date(Today(), 'DD-MM-YYYY');

for i = 0 to 5

let test = addmonths ($(vActualYearAndMonth),-$(i));

NEXT i

As today is 01-12-2014, it should return:

01-12-2014

01-11-2014

01-10-2014

01-9-2014

01-8-2014

but it returns

05-12-99

05-11-99

05-10-99

05-9-99

05-8-99

Do you have an idea why is this happening?

1 Solution

Accepted Solutions
anbu1984
Master III
Master III

set errormode = 0;

Let vActualYearAndMonth        = Today();

for i = 0 to 5

let test = Date(addmonths ('$(vActualYearAndMonth)',-$(i)), 'DD-MM-YYYY');

NEXT

View solution in original post

2 Replies
morganaaron
Specialist
Specialist

Hi Nemanja,

I think your addmonths statement is calculating the value of vActualYearAndMonth rather than taking it as a date - wrapping it in the DSE will cause it to return it's numerical value of -2025.

Try removing the $( ) from the variable name and see if that works.

Thanks.

anbu1984
Master III
Master III

set errormode = 0;

Let vActualYearAndMonth        = Today();

for i = 0 to 5

let test = Date(addmonths ('$(vActualYearAndMonth)',-$(i)), 'DD-MM-YYYY');

NEXT