Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Addmonths() function not working properly.

   Hi Community,

I have tried many examples to understand Addmonths() function. when i tried Examples which were mentioned in the reference manua , i got exact output.

But when i tried other examples with different modes , output is same.

Can any one explain What is the issue????

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

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

Please explain , why two outputs are same Even modes are different????

 

1 Solution

Accepted Solutions
Not applicable
Author

Satti,

It is your understanding of the situation that is flawed, not the computer program

y=addmonths('2013-1-27',1,1); - gives 2/27.

y=addmonths('2013-1-28',1,1); - gives 2/25.

y=addmonths('2013-1-29',1,1); - gives 2/26.

y=addmonths('2013-1-30',1,1); - gives 2/27

y=addmonths('2013-1-31',1,1); - gives 2/28

In short, 'mode 1' functions only at the end of the month. Otherwise it functions as normal.

View solution in original post

15 Replies
Not applicable
Author

Thanks for Reply 

Not applicable
Author

Because you dont need the last node..

Addmonths(2012-1-20,1) gives you 2012-02-20 // NextMonth

Addmonths(2012-1-20,0) will give you the same // SameMonth

Addmonths(2012-1.20,-1) vil give you 2012-12,20 // PreviousMonth

Ofcause with '' around date

If your smart you will make a ThisDate variable

LET ThisDate = date(Today(), 'YYYY-MM-DD')

LET PreviousMonth = Addmonths(ThisDate,-1)

For an example

Not applicable
Author

Try this

=date(addmonths(Date,-1),'DD\MM\YYYY')

That will give you last month (-1)

Not applicable
Author

Mode is only used when the day for the date passed should be relative to the the day it ends up in

If you do AddMonths('2013-02-28', 1, 0) the function will return '2013-03-28' using the datepart from called month.

But if you use AddMonths('2013-02-28', 1, 1) it uses the relative date (28 being the last day of february) to set the last date of march wich is '2013-03-31'

This calculation is only performed when the day-part of the called date is >= the day-part of the resulting date OR vice versa. Usually day 28-31.

Cheers

Not applicable
Author

 

let

y=addmonths('2013-1-20',1,1);

Expected ouput: 2013-2-17  

but i got output : 2013-2-20 ... is it correct ????

danielrozental
Master II
Master II

Yes, that is the correct output. Please check the help.

Not applicable
Author

 

let

y=addmonths('2013-1-20',1,1);

Expected ouput: 2013-2-17  

but i got output : 2013-2-20 ... is it correct ????

Not applicable
Author

yes

Not applicable
Author

Hi Daniel ,

but i got output : 2013-2-20 ... is it correct ????

As per qlikview help it is wrong.

I have used mode 1.

Please execute it once then you will understand ..