3 Replies Latest reply on Jan 17, 2012 11:02 AM by LaRetta_1

# Newbie

Newbie

### Post

I am new to File Maker Pro and need probably a simple question. I need to compute a student's age based on their birthdate for no matter when I ask for the information. For example if I enter 4/12/92, and I put in a column that says Today's date, will I be able to get the students age oas of that date? How can I do this? Thanks.

• ###### 1. Re: Newbie

[From others before me]

You can use this calculation to compute their age now:

Case ( DOB and Get ( CurrentDate ) ; Year ( Get ( CurrentDate ) ) - Year ( DOB ) - ( DayOfYear (Get ( CurrentDate ) ) < DayOfYear ( DOB ) ) )

Make sure you set the storage option to be 'Unstored' when you define the calculation.

If you substitute the incidences of 'Get ( CurrentDate )' with the field 'DateIWantToCalculateAt' then it will work for then, too.

• ###### 2. Re: Newbie

Actually this calc can break because DayOfYear() evaluates differently for different years (depending upon whether the year has a leap year).

If today is 12/31/2011 and DOB is 12/31/2000, your calc will evaluate to 10 when it should be 11.  The reason is because DayOfYear for 12/31/2000 is 366 but DayOfYear for 12/31/2011 is 365.  If you change the DOB to 12/31/2001, your calc correctly evaluates to 10.  3/15/2000 (DayOfYear 75) compared to 3/15/2005 (DayOfYear 74).

I believe that you meant to use something like this (in all these calculations, replace Today with Get ( CurrentDate ) and replace theDate with your DOB and set the calculation to date  OOOPS I MEAN NUMBER, check 'do not store calculation results' in Storage Options so the calc will automatically update.  These calculatioins will properly account for leap year:

Year ( Today ) - Year ( theDate ) - ( ( Month ( Today ) + Day ( Today ) / 100 ) < ( Month ( theDate) + Day ( theDate) / 100 ) )

… but I prefer using Let() to keep it clear:

Let ( [
now = Today ;
then = theDate ;
thisYear = Date ( Month ( then ) ; Day ( then ) ; Year ( now ) )
] ;
Year ( now ) - Year ( then ) - ( thisYear > now )
)

LaRetta

• ###### 3. Re: Newbie

Hi Richard,

I just realized that you did not specify whether you wanted years only or years, months and days.  If you want years, months and days, I must tell you that it is a highly complex issue. For reference, the best collection of discussions on Age calculations can be found on Comment’s page here:  http://attic.fmforums.com/forum/userpage.php?uid/21152/ … scroll down to Age.  Comment’s page also shows the best techniques for many other issues you might face and I suggest folks bookmark it.   Particularly read this:  http://fmforums.com/forum/topic/49319-birthday-calculator-beta/#238121

I have created two calculations which come the closest in all that I have reviewed over the years.  Again, replace theDate with birthday or whatever date is your older date.  And replace Today with Get (CurrentDate) or your newer date.  Result of calculation should be text and uncheck ‘do not store calculation results…’ in Storage Options so they update.  They account for leap years as well …

Full display ( example: 6 years, 0 months, 3 days ... or even  0 years, 0 months, 0 days ):

Case ( StartDate and EndDate and StartDate  ≤ EndDate ;
Let ( [
start = StartDate ;
end = EndDate ;
startlen = Day ( Date ( Month ( start ) + 1 ; 0 ; Year ( start ) ) ) ;
x = 12 * ( Year ( end ) - Year ( start ) ) + Month ( end ) - Month ( start ) - ( Day ( end ) < Day ( start ) ) ;
y = Div ( x ; 12 ) ;
m = Mod ( x ; 12 ) ;
d = Case ( Day ( start ) > Day ( end )  ; startlen +  Day ( end )  - Day ( start )  ; Day ( end ) - Day ( start ) )
] ;
y & " year" & Case ( y  ≠ 1 ; "s" )  & ", " &
m & " month" & Case ( m  ≠ 1 ; "s" ) & ", " &
d & " day" & Case ( d  ≠ 1 ; "s" )
) // END LET
) // END CASE

Limited display ( example: 6 years, 1 month, 3 days ):note that if birthday is same as the current date then the ‘Limited’ calc will produce nothing because it would be 0 years, 0 months, 0 days but since we do not want it to display the increments if zero, none would display.

Case ( StartDate and EndDate and StartDate  ≤ EndDate ;
Let ( [
start = StartDate ;
end = EndDate ;
startlen = Day ( Date ( Month ( start ) + 1 ; 0 ; Year ( start ) ) ) ;
x = 12 * ( Year ( end ) - Year ( start ) ) + Month ( end ) - Month ( start ) - ( Day ( end ) < Day ( start ) ) ;
y = Div ( x ; 12 ) ;
m = Mod ( x ; 12 ) ;
d = Case ( Day ( start ) > Day ( end )  ; startlen +  Day ( end )  - Day ( start )  ; Day ( end ) - Day ( start ) ) ;
string = Case ( y ; y & " year" & Case ( y  ≠ 1 ; "s" ) & ", " ) &
Case ( m ; m & " month" & Case ( m  ≠ 1 ; "s" ) & ", " ) &
Case ( d ; d & " day" & Case ( d  ≠ 1 ; "s" ) )
] ;
LeftWords ( string ; Length ( string ) )
) // END LET
) // END CASE

I hope this all is helpful.