Brian Dunning's FileMaker Custom Functions

Months_Diff ( date1 ; date2 )

Months difference part between two dates.

  Average rating: 4.0 (34 votes) Log in to vote

Ron Smith   Ron Smith - Show more from this author

Share on Facebook Share on Twitter

  Sample input:
Months_Diff ( 7/14/1958 , 4/15/2015 )
  Sample output:
9

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

This is the months difference between two dates which should be entered in with the earlier date first. Ex:

7/14/1958 - 9/8/2006 = 48years 6months 11days

This function could use similar coding as in my Days_Diff function which allows dates in no particular order.

 

Comments

Aaron Beck   Aaron Beck, Lees Summit
Jul 22, 2013
Not sure how this meets anyones needs but the months difference between dates should take in to account the years. Even the sample input shown and output shown is not accurate. I am looking for the true number of months between 2 dates. Take a look at result in that 48 years 6 months and 11 days. Years are irrelevant in that it is a constant 12. July to September is not 6 months no matter how many leap years there are.
 
Ron Smith   Ron Smith
Jul 22, 2013
It makes a great deal of difference when I am checking children and I need their years, month, and days. I use the three together and have for years in my custom EMR.

Warmest regards,

Ron
 
Aaron Beck   Aaron Beck, Lees Summit
Jul 22, 2013
This works to get true months touched between the two dates:

Abs(Case(
Year(Date2)=Year(Date1); If(Month(Date2) <> Month(Date1);1) + Abs(Month(Date2) - Month(Date1));
Year(Date2)>Year(Date1); 0 + If((GetAsDate(Date1))<GetAsDate(Date2); 1 + Months_Diff(Date ( Month(GetAsDate(Date1)+31) ; 1 ; Year(GetAsDate(Date1) +31) ); Date2));
Year(Date2)<Year(Date1); 0 + If((GetAsDate(Date2))<GetAsDate(Date1); -1 - Months_Diff(Date ( Month(GetAsDate(Date1)-31) ; 1 ; Year(GetAsDate(Date1) -31) ); Date2))

))
 
Tom Guise   Tom Guise, Smart Wolf
Apr 15, 2015
The following formula is directly from the FileMaker help archive...

(Year(Date2 + 1) - Year(Date1 + 1)) * 12 + (Month(Date2 + 1) - Month(Date1 + 1)) - If (Day (Date2 + 1) = Day (Date1), 0, If (Day (Date2 + 1) < Day (Date1+1), 1, 0))
 
Ron Smith   Ron Smith
Apr 15, 2015
Hi, Aaron. There appears to be a typo in that example output. I checked the code and it does work and is correct. I'll fix the example. I apologize for that error. Here is what I get when I look at my information in my EMR at this moment:

My date of birth: 7/14/58
Today's date: 4/15/2015

This calculates to 56 years 9 months 1 day.

Now each of the days and months and years function to give you what you need for years, months, and days. For me in Pediatrics, for example, I must know that a child is 12 months to the day before I give the MMR or it won't count and they'll have to get that first vaccine again.

Use the parts that you need, but I use the three together.

Warmest regards,

Ron Smith, MD
 

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 20 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: