Why doesnt addMonths([%EndOfCurrentMonth%],-1) always give the end of the previous month?

0
For months that end on the 28th, 29th, or 30th day, addMonths([%EndOfCurrentMonth%],-1)  will give you the 28th, 29th, or 30th day of the previous month. However, addMonths([%EndOfCurrentMonth%],-2) will give you the end of the month two months ago. Is this expected behaviour for this date function? 
asked
2 answers
3

The addMonths (-1) will add or substract a month from your input date value. The EndOfCurrentMonth token is just your parameter/date time value. It's not specific logic that will check if it's the latest day of the month if you add/substract months. Maybe you want to go to previous month of this specific day (for example 8-3-2024), you should be able to substract a month as well. So, it does make sense.

 

You could solve it by doing addDays([%BeginOfCurrentMonth%], -1). This should always give you the latest day of the previous month.

 

answered
1

In the function addMonths(Parameter 1, Parameter 2)  Parameter 2 is the number of months to add or, in your case, subtract. 

So in your example the "-1" means minus one month, and "-2" means minus 2 months. 

I'd say the function is behaving as expected. 

answered