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 ( Birth; theDate; Format )

Rate this function:

Discuss this Custom Function

Geoff Wells, DataIsland Software LLC
http://www.dataisland.com

Calculates Age in three formats

Sample Input:
 Age ( 5/14/1946; 5/11/2004; 3 )
Sample Output:
 57 years and 11 months, and 27 days

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

## Description:

The Age function will calculate a persons age, on any date, in three different formats -

1 / Years
2 / Years and Days
3 / Years, Months and Days.

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:

There's another way that bypasses the Case statement.

leapFactor = If ( Mod ( Year ( theDate ) ; 400 ) = 0 ; 1 ; 0 ) // 'century' years divisible by 400 are leap years
- If ( Mod ( Year ( theDate ) ; 100 ) = 0 ; 1 ; 0 ) // 'century' years not divisible by 400 are not leap years
+ If ( Mod ( Year ( theDate ) ; 4 ) = 0 ; 1 ; 0 ) // years divisible by 4 are leap years

A year that is divisible by 400 (e.g. 1600, 2000) will evaluate to 1 - 1 + 1 = 1.
A year that is divisible by 100 but not by 400 (e.g. 1300, 1900) will evaluate to 1 - 1 + 0 = 0.
A year that is divisible by 4 but not by 100 (e.g. 1972, 1988) will evaluate to 1 - 0 + 0 = 1.
Any other year (i.e. not a leap year) will evaluate to 0 - 0 + 0 = 0.

Just another way to skin this particular cat.

Rob Woof, Sydney/Australia
August 11, 2010 8:48pm

No need to do this at all: FileMaker will handle leap years itself if you use it's own date comparisons.
Go look at http://www.briandunning.com/cf/518

That one lets you pick a comparison date (just use Get( CurrentDate ) for the second parameter if you want current age), handles negative age comparisons, and returns multiple formats.

Also, it has the decided advantage of actually returning correct values, even when dealing with leap years and on the actual birthday anniversary because it uses FileMaker's own date comparisons to get it right.

Daniel A. Shockley, New York, NY
May 04, 2011 11:16am

Doesn't seem to work for Leap Years. Try 2008 and Feb28th then Feb29th then Mar1. It skips a date.

David, Sacramento
December 10, 2013 8:51pm

To be perfect, we also need to take in account the "combination" of the 4, 100 and 400.

Let (

leapFactor =

Case (

// Divisible by 4
// not by 100 and 400, such as 2012, 2016
Mod ( Year ( theDate ) ; 4 ) = 0 and
Mod ( Year ( theDate ) ; 100 ) ≠ 0 and
Mod ( Year ( theDate ) ; 400 ) ≠ 0 ;
1 ; // Leap Year

// Divisible by 4 and 100
// not by 400, such as 2200, 2300, 2500, 2600 are common years
Mod ( Year ( theDate ) ; 4 ) = 0 and
Mod ( Year ( theDate ) ; 100 ) = 0 and
Mod ( Year ( theDate ) ; 400 ) ≠ 0 ;
0 ; // Common Year

// Divisible by 4 and 100 and 400
// such as 1600, 2000, 2400 are leap years
Mod ( Year ( theDate ) ; 4 ) = 0 and
Mod ( Year ( theDate ) ; 100 ) = 0 and
Mod ( Year ( theDate ) ; 400 ) = 0 ;
1 ; // Leap Year

0 // else are Common Years

)
) ;

Ukyo Matsushita, Tokyo/Japan
September 15, 2016 1:53am

Hi everyone - maybe someone is still reading this... Personally and probably many other have used this function for years...

Here's another issue with the leap years... even in the current version.

Take: Birth 7th of June 2012 and today a June 7th 2018.

In this exception it comes up with 5 Years, 364 Days - while apparently the child is 6 years old. Same is true for June 7th 2016.

Since I didn't want to look too deeply into the formulas.. Maybe someone has a solution....

Alexis Gehrt, Switzerland
June 13, 2018 6:45am