Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
vikasmahajan

Addmonths function

Dear All,

Can anybody explain  addmonths with mode in details ?

Thanks

Vikas

Hope this resolve your issue.
If the issue is solved please mark the answer with Accept as Solution & like it.
If you want to go quickly, go alone. If you want to go far, go together.
14 Replies
Gysbert_Wassenaar

The addmonths creates a new date from the input date by adding or subtracting the number of months you specify as the second argument to the function.

The Help file is pretty clear imho:

AddMonths(startdate, n , [ , mode] )

Returns the date occurring n months after startdate or, if n is negative, the date occurring n months before startdate.

By specifying a mode (0 if omitted) the date is set to either the unmodified day of the specified month (mode=0) or the calculated day as derived from the end of the month (mode=1).

Examples:

addmonths ('2003-01-29',3) returns '2003-04-29'

addmonths ('2003-01-29',3,0) returns '2003-04-29'

addmonths ('2003-01-29',3,1) returns '2003-04-28'

addmonths ('2003-01-29',1,0) returns '2003-02-28'

addmonths ('2003-01-29',1,1) returns '2003-02-26'

addmonths ('2003-02-28',1,0) returns '2003-03-28'

addmonths ('2003-02-28',1,1) returns '2003-03-31'


talk is cheap, supply exceeds demand
alexandros17
Partner - Champion III
Partner - Champion III

you can understand the functio with this example:

addmonths
('2003-01-29',1,0)
returns '2003-02-28'

addmonths
('2003-01-29',1,1)
returns '2003-02-26'

in the second case I'm Adding a month to january but the month I'm adding is february that has 28 days that summed to january 29th is february 26 ....

Hope it helps

Not applicable

Hello Vikas,

Gysbert has explained very well, I would like to explain the results :

addmonths ('2003-01-29',3) returns '2003-04-29'

--will add 3 months

addmonths ('2003-01-29',3,0) returns '2003-04-29'

--will add 3 months

addmonths ('2003-01-29',3,1) returns '2003-04-28'

--will add 3 months, BUT enddate of Jan 2003 is 2003-01-31 and input date is 2 days less. So date returned is 3 months, that is April 2003 enddate(2003-04-30), but 2 days less which will give 2003-04-28

Thanks,

angad

vikasmahajan
Author

Thanks for clearing doubts

Please check my expression using Mode my problem is solved

I used following expression for last year  and use 1 mode for hadling leap year

addmonths(max({$<FiscalYear={$(=max(FiscalYear))}>}[Posting Date]),-12,1))

Whether it is ok ?

Regards

Vikas

Hope this resolve your issue.
If the issue is solved please mark the answer with Accept as Solution & like it.
If you want to go quickly, go alone. If you want to go far, go together.
Not applicable

Hi guys,

Did great explanation..

Then think about this once

 

 

let

x=addmonths('2012-1-20',1,0);  //2012-2-20

let  y=addmonths('2012-1-20',1,1); //2012-2-20

i have checked these two dates. Result is same even mode is different .

Plz explain once .. why it is getting same.

Not applicable

Hi guys,

Did great explanation..

Then think about this once

 

 

let

x=addmonths('2012-1-20',1,0);  //2012-2-20

let  y=addmonths('2012-1-20',1,1); //2012-2-20

i have checked these two dates. Result is same even mode is different .

Plz explain once .. why it is getting same.

Not applicable

Hi guys,

Did great explanation..

Then think about this once

 

 

let

x=addmonths('2012-1-20',1,0);  //2012-2-20

let  y=addmonths('2012-1-20',1,1); //2012-2-20

i have checked these two dates. Result is same even mode is different .

Plz explain once .. why it is getting same.

Not applicable

try same example with different modes.Try examples which are not mentioned in the qlikview reference manual

for Eg:

 

let x=addmonths('2012-1-20',1,0)

;

let y=addmonths('2012-1-20',1,1);

Please explain , why two outputs are same????

Not applicable

try same example with different modes.Try examples which are not mentioned in the qlikview reference manual

for Eg:

 

let x=addmonths('2012-1-20',1,0)

;

let y=addmonths('2012-1-20',1,1);

Please explain , why two outputs are same????