# Number of months difference

This topic is 7155 days old. Please don't post here. Open a new topic instead.

## Recommended Posts

Hi, How do I do a calculation for the number of month between 2 dates

Thanks

Simon

Script

Set Field [

##### Share on other sites

Calculation questions should go in the Define Fields forum, but here are two possible solutions:

Month(DateTo) - Month(DateFrom)

or

Truncate((DateTo - DateFrom / 30, 0)

Depends on how you define "number of months between".

##### Share on other sites

Ender said:

Month(DateTo) - Month(DateFrom)

Oops, This does not work if dates are from different years.

##### Share on other sites

Hi Ender,

Ender said:

Truncate((DateTo - DateFrom / 30, 0)

to this to get it to work:

Truncate((Next Payment Due - Payment Date) / 30, 0)

???

##### Share on other sites

((Year (DateTo) - Year (DateFrom)) * 12 ) + Month (DateTo) - Month (DateFrom)

I'm reluctant to use any date calculations that assume a month is 30 days or a year is 365; it's hard-coding errors and inaccuracies into the system.

FMP has date functions that can work all this stuff out correctly, automatically taking into account leap years and other vagaries of the calendar.

##### Share on other sites

My thought on that was getting an answer to this:

DateFrom: 2/15/2004

DateTo: 4/1/2004

One might say only "1 month" had passed during that period, because we tend to truncate when we talk about duration (I say I'm 30 years old, not 30.5) But of course you are correct to take into account different length months. If the dates are:

DateFrom: 2/15/2004

DateTo: 3/15/2004

The result should be "1 month". My calc did not take this into account.

##### Share on other sites

Oops, I have a typo in my calculation in the script

Lee Smith said:

Script

Set Field [

##### Share on other sites

This topic is 7155 days old. Please don't post here. Open a new topic instead.

## Create an account

Register a new account

×
×
• Create New...