17
Views
8
Comments
Solved
Add months behaviour
Application Type
Reactive
Service Studio Version
11.9.2 (Build 34232)

Hi

I am using add months builtin function.suppose I am entering 30th Dec 2020 and trying to add 1 month with help of add months built in function.and it returning proper output 30 th January 2021 but when I am passing 28th February 2021 and trying to add 1 month then it is returning 28 th March 2021 but it should be 30th March 2021.is it right behaviour?

mvp_badge
MVP
Rank: #2
Solution

Hi Arkyadeep,

If you're goal is to get the last days of every month, you could take the first day of the next month, and subtract one day. So if you have a certain last day, add one day, add one month, then subtract one day, and so on.

If you want to have all 30th of all months except for February, you'll have to come up with a smarter algorithm, that is actually aware of February having 28 or 29 days. You could also try to see if the NewDate function turns 30 February into 28, and use that.

Rank: #70

Hi Arkyadeep,


Yes, March 28th is 1 month later than February 28th.

If you are looking to add 30 days you can use the AddDays built-in functionality.


Regards,
João

mvp_badge
MVP
Rank: #2
Solution

Hi Arkyadeep,

If you're goal is to get the last days of every month, you could take the first day of the next month, and subtract one day. So if you have a certain last day, add one day, add one month, then subtract one day, and so on.

If you want to have all 30th of all months except for February, you'll have to come up with a smarter algorithm, that is actually aware of February having 28 or 29 days. You could also try to see if the NewDate function turns 30 February into 28, and use that.

Rank: #491

Yeah, it adds 1 month to the date you chose as start date, and 1 month = 30 days.

To get end of the date I think you should try your own function. 

For example, 

  1. Start with 28 Feb 2021
  2. Add 2 month to date No.1 = 28 Apr 2021
  3. Get first of the date No.2 = 1 Apr 2021
  4. Subtract 1 date from the date No.3 = 30 Mar 2021

Hope this help