Shopping Cart

Search:

Signup

Contact

FileMaker is a registered trademark of FileMaker, Inc. in the U.S. and other countries.

# FileMaker Pro Custom Functions

age ( date1 ; date2 )

Rate this function:

Discuss this Custom Function

Winfried Huslik, Huslik Verlag GmbH
http://fmdiff.com

Calculates the number of years, months, and days between any two dates

Sample Input:
 age ("7/27/1980" ; "7/26/2006" )
Sample Output:
 25 10 30 25 years, 10 months, and 30 days

Then copy & paste into FileMaker Advanced's Edit Custom Function window.

## Description:

This calculation takes into account different days in a month as well as leap years and negative distances. The result is provided as a line separated list containing Years, Months, Days. To access these results use LeftValues (), MiddleValues (), and RightValues () respectively. Use at your own risk.
<br />This formula is meant as a replacement for the one given at <a href="http://filemaker.custhelp.com/cgi-bin/filemaker.cfg/php/enduser/std_adp.php?p_faqid=5532&p_created=1129657697&p_sid=-ERH76bi&p_lva=&p_li=&p_topview=1">FileMaker Custom Help</a><br />

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

This is my Custom Function and I want to edit it

## Discuss:

Function seems to work dandy! One minor quibble is that the fourth value output always assumes a plural value (i.e. "1 Days"). To fix that, you can change the last output line to:

y & " year" & If(y = 1; ""; "s") & ", " & m & " month" & If(m = 1; ""; "s") & ", and " & d & " day" & If(d = 1; ""; "s") & ¶

Regardless, I rated this function 5 / 5.

HazMatt, Blaine, MN USA
March 29, 2013 2:25pm

Awesome Calculation. You can also try

Full Age
FullAge (calculation, text result) =
GetAsText ( Year ( Get ( CurrentDate ) ) - Year ( Birthdate ) - If ( Get ( CurrentDate ) < Date ( Month ( Birthdate ) ; Day ( Birthdate ) ; Year ( Get ( CurrentDate ) ) ) ; 1 ; 0 ) ) & " Years, " & GetAsText ( Mod ( Month ( Get ( CurrentDate ) ) - Month ( Birthdate ) + 12 - If ( Day ( Get ( CurrentDate ) ) < Day ( Birthdate ) ; 1 ; 0 ) ; 12 ) ) & " Months, " & GetAsText ( Day ( Get ( CurrentDate ) ) - Day ( Birthdate ) + If ( Day ( Get ( CurrentDate ) ) ≥ Day ( Birthdate ); 0 ; If ( Day ( Get ( CurrentDate ) - Day ( Get ( CurrentDate ) ) ) < Day ( Birthdate ) ; Day ( Birthdate ) ; Day ( Get ( CurrentDate ) - Day ( Get ( CurrentDate ) ) ) ) ) ) & " Days "

Ganesh, Carmel, CA
May 06, 2013 9:33pm

Just saw this on a post at fmlayouts.com (unrelated to the age calculation issue) but the post by loSTaNT had a file that had an awesome age calculation field that works and is much simpler as well. You can download the file at: http://fmlayoutmode.com/wp/?p=1356

and the referenced calculation field is:
Let ( [
@cd = Get ( CurrentDate )
; @cdConverted = Year ( @cd ) + Month ( @cd ) / 100 + Day ( @cd ) / 10000
; @bdConverted = Year (Birthdate ) + Month (Birthdate ) / 100 + Day (Birthdate ) / 10000
] ;

Int ( @cdConverted - @bdConverted )

)

Ganesh, Carmel, CA
May 31, 2013 9:19am

It works and I'm happy with the function.

a) Accuracy - I've tested it against "FullAge (calculation, text result)" mentioned in this discussion by Ganesh on May 6 2013. The two agree most of the time. Sometimes there's a day's difference. I assume that's because there's room for defining a month as 30/31 days.

b) Absolute Value - The "FullAge (calculation, text result)" will give a negative number if you swap the dates around. This function age ( date1 ; date2 ) always assumes you want a positive figure.

c) Parameters - I like that it passes back info as 4 separate parameters : Y,M,D,Sentence

d) Singular/Plural - Make this adjustment to the last part of the calculation. It ensures that if there is one day/month/year that system returns "month" instead of "months":
y * neg & ¶ &
m * neg & ¶ &
d * neg & ¶ &
y & If (y = 1; " year, " ;" years, " )&
m & If (m=1; " month & ";" months & " )&
d & If (d=1;" day";" days" ) & ¶

KevinSmith, London UK
January 22, 2014 7:55am

I brought it over as is, and then made a duplicate, named it age_abbreviated, and changed the output to:

y * neg & " Y, " &
m * neg & " M, " &
d * neg & " D"

So output goes to something like "34 Y, 3 M, 13 D" which fits nicer into the field I set up.

Very appreciative of this function!

Dave, Birmingham, AL
June 18, 2015 2:23pm