There is no built-in function for that. And is not easy to define one, as different months have different number of days, and February changes its number of days depending on the year.

You have DiffDays, that will give you the number of days between 2 dates.

If you define a month as 30 days, you can than divide the result of DiffDays by 30 and find a rough approximation.

Is there a way to calculate the different months between two dates in the outsystems?

Hi Yi !

you can also add a function to calculate the integer difference if that's no issue for you. So, if you create a function in Outsystems with 2 input parameters (startdate, enddate), you should be able to get the difference in months with the following expression:

But depending on what is being requested, like not the exactly difference in months, but only a number that indicate if the second date is in the same month as the first on in which month after the first, it works perfectly.

I would get the years and months for each date and save 12*years+month as the months that existed since the start.

Months1=12*Year(Date1)+Month(Date1)

Months2=12*Year(Date2)+Month(Date2)

The formula abs(Months2-Months1)+1 will say how many months exist. 1 if they are in the same month, 2 if they are consecutive months, 3 if there is a month between, and so on.

I use the absolute because month1 can be greater or smaller than month2.

Is there a way to calculate the different months between two dates in the outsystems?

Hi Yi Wang,

To calculate the difference between months between 2 dates, you have to consider that you'll have a decimal value when the difference is not an exact Month.

I've made a function to perform what you need:

If you create a function with that exact code, you should be able to have what you need.

I tried to comment everything in order for you to understand what it's being done on each step.

Is there a way to calculate the different months between two dates in the outsystems?

Hi Yi Wang,

To calculate the difference between months between 2 dates, you have to consider that you'll have a decimal value when the difference is not an exact Month.

I've made a function to perform what you need:

If you create a function with that exact code, you should be able to have what you need.

I tried to comment everything in order for you to understand what it's being done on each step.

Is there a way to calculate the different months between two dates in the outsystems?

Hi Yi Wang,

To calculate the difference between months between 2 dates, you have to consider that you'll have a decimal value when the difference is not an exact Month.

I've made a function to perform what you need:

If you create a function with that exact code, you should be able to have what you need.

I tried to comment everything in order for you to understand what it's being done on each step.