Qlik Community

QlikView App Development

Discussion Board for collaboration related to QlikView App Development.

Announcements
QlikWorld, June 24-25, 2020. Free virtual event for DI and DA gurus. Register Today
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Champion
Champion

Addmonths function

Dear All,

Can anybody explain  addmonths with mode in details ?

Thanks

Vikas

14 Replies
Highlighted
MVP & Luminary
MVP & Luminary

Re: Addmonths function

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
Highlighted

Re: Addmonths function

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

Highlighted
Not applicable

Re: Addmonths function

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

Highlighted
Champion
Champion

Re: Addmonths function

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

Highlighted
Not applicable

Re: Addmonths function

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.

Highlighted
Not applicable

Re: Addmonths function

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.

Highlighted
Not applicable

Re: Addmonths function

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.

Highlighted
Not applicable

Re: Addmonths function

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????

Highlighted
Not applicable

Re: Addmonths function

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????