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

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
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.

2023-06-14 08-52-52
Arkyadeep Bharadwaj
based on date and EMI tenure i have to generate EMI date so if user entered 30th january then it is generating below emi date.but after february it is changing to 28th of every month it should be 30th of every month because user entered 30th of every month.

 

2018-10-29 08-31-03
João Marques
 
MVP

Hi Arkyadeep,


You are adding one month to the result of the previous row. So in your case, you get:

Row 1: 30-11-2020

Row 2: 30-11-2020 + 1 month = 30-12-2020

Row 3: 30-12-2020 + 1 month = 30-01-2021

Row 4: 30-01-2021 + 1 month = 28-02-2021

Row 5: 28-02-2021 + 1 month = 28-03-2021


You can always use the start date from your starting row. So it would be like this:

Row 1: 30-11-2020

Row 2: 30-11-2020 + 1 month = 30-12-2020

Row 3: 30-11-2020 + 2 months = 30-01-2021

Row 4: 30-11-2020 + 3 months = 28-02-2021

Row 5: 30-11-2020 + 4 months = 30-03-2021


Regards,
João

2018-10-29 08-31-03
João Marques
 
MVP

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

2023-06-14 08-52-52
Arkyadeep Bharadwaj

But the problem I have 30th January and after that I have to add 1 month for every date suppose if u choose 30th January then recurring date will 28th Feb,30th March,30 th April but if I use adddays,30 then I think after january it will generate 2nd March.

2018-10-29 08-31-03
João Marques
 
MVP

Hi Arkyadeep,


So you want to generate dates by adding one month every time and your concern is that after January 30th, you wind up getting February 28th and then you get stuck in March 28th, instead of March 30th, is that it?

If that is the case, I would fix the starting date, let's say January 30th, and then add 1 month in the first iteration, 2 months on the second, and so on, but always to the starting date January 30th. In this case, you don't get stuck in February.


Hope it helps.


Regards,

João

2023-06-14 08-52-52
Arkyadeep Bharadwaj

based on date and EMI tenure i have to generate EMI date so if user entered 30th january then it is generating below emi date.but after february it is changing to 28th of every month it should be 30th of every month because user entered 30th of every month.

 

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
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.

2023-06-14 08-52-52
Arkyadeep Bharadwaj
based on date and EMI tenure i have to generate EMI date so if user entered 30th january then it is generating below emi date.but after february it is changing to 28th of every month it should be 30th of every month because user entered 30th of every month.

 

2018-10-29 08-31-03
João Marques
 
MVP

Hi Arkyadeep,


You are adding one month to the result of the previous row. So in your case, you get:

Row 1: 30-11-2020

Row 2: 30-11-2020 + 1 month = 30-12-2020

Row 3: 30-12-2020 + 1 month = 30-01-2021

Row 4: 30-01-2021 + 1 month = 28-02-2021

Row 5: 28-02-2021 + 1 month = 28-03-2021


You can always use the start date from your starting row. So it would be like this:

Row 1: 30-11-2020

Row 2: 30-11-2020 + 1 month = 30-12-2020

Row 3: 30-11-2020 + 2 months = 30-01-2021

Row 4: 30-11-2020 + 3 months = 28-02-2021

Row 5: 30-11-2020 + 4 months = 30-03-2021


Regards,
João

2023-10-16 05-50-48
Shingo Lam

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

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.