Age (birthDate;theDate;format)

This function provides three ways to display a persons age - just years, years and days, and years, months and days. It is accurate in most situations but the second and third formats do not fully account for leap years. It does take leap years into account but there is no way to accurately express the age of someone born on February 29th in years, months and days.

Age (birthDate;theDate;format)

// This is a Custom Function version of calculations provided in "Advanced FileMaker Pro 5.5" by Chris Moyer and Bob Bowers. This formula differs slightly from the ones in the book which do not account for leap years.

Let ( [

leapFactorDate = Case (

Mod ( Year ( theDate ) ; 100 ) = 0 ; // a century year

If ( Mod ( Year ( theDate ) ; 400 ) = 0 ; 1 ; 0 ) ; // leap year only every 4 century years

Mod ( Year ( theDate ) ; 4 ) = 0 ; 1 ; 0 // second case - leap year every fourth year

) ; // end case

leapFactorBirth = Case (

Mod ( Year ( birthDate ) ; 100 ) = 0 ; // a century year

If ( Mod ( Year ( birthDate ) ; 400 ) = 0 ; 1 ; 0 ) ; // leap year only every 4 century years

Mod ( Year ( birthDate ) ; 4 ) = 0 ; 1 ; 0 // second case - leap year every fourth year

) // end case

] ; // end let variable declaration

Case (

// Age in years

format = 1 ; Year ( theDate ) - Year ( birthDate ) - ( ( DayOfYear ( theDate ) - leapFactorDate ) < DayOfYear ( birthDate ) - leapFactorBirth );

// Age in years and days

format = 2 ; Year ( theDate ) - Year ( birthDate ) - ( ( DayOfYear ( theDate ) - leapFactorDate ) < DayOfYear ( birthDate ) - leapFactorBirth ) & " years and " & Case (

( DayOfYear ( theDate ) - leapFactorDate ) ≥ DayOfYear ( birthDate - leapFactorBirth ) ;

DayOfYear ( theDate ) - leapFactorDate - DayOfYear ( birthDate - leapFactorBirth ) ;

DayOfYear ( theDate ) + ( DayOfYear ( Date ( 12 ; 31 ; Year ( theDate ) ) - leapFactorDate ) - DayOfYear ( birthDate ) ) - leapFactorBirth ) & " days" ;

// Age in years, months and days

format = 3 ; Year ( theDate ) - Year ( birthDate ) - ( ( DayOfYear ( theDate ) - leapFactorDate ) < DayOfYear ( birthDate ) - leapFactorBirth ) & " years and " & Mod ( Month ( theDate ) - Month ( birthDate ) + 12 - (Day ( theDate ) < Day ( birthDate ) ) ; 12 ) & " months, and " & (theDate - Date ( Month ( theDate ) - (Day ( theDate ) < Day ( birthDate ) ) ; Day ( birthDate ) ; Year ( theDate ) ) ) & " days"

) // end case

) // end let

Contact Us | Privacy | Policies

Copyright © 2006 DataIsland Software LLC. All rights reserved.

Notice: Product specifications and availability are subject to change without notice.