Calculate a Person's Age

From HotDocs Wiki

Jump to: navigation, search

To calculate a person's age, you must first determine the birth date. Then, you must determine the date for which you want to calculate the person's age. If you want the age as of the date you're calculating, you can use the AGE expression. Otherwise, if you want to find the age on a given date, you will need a separate variable for that date and you must use the YEARS FROM expression.

Contents

Examples

The following computations calculate a person's age on different dates. In these computations:

Birth Date is the date of birth.

Date Var is the date on which you want to calculate the age.

Years is a temporary Number variable used for the years portion of an age. (See Create a Temporary Variable.)

Months is a temporary Number variable used for the months portion of an age.

Weeks is a temporary Number variable used for the weeks portion of an age.

Days is a temporary Number variable used for the days portion of an age.

Note: For young children, you may want to calculate the age in months instead of years. The third example calculates age in months using the MONTHS FROM expression if the child is less than two years old. The last two examples take the age calculation even further, breaking up a person's age into years, months, weeks, and days

Age as of today

AGE( Birth Date )
//(alternative)
YEARS FROM( Birth Date, TODAY )

Age on a given date

YEARS FROM( Birth Date, Date Var )

Age in months if less than 2 years old; otherwise age in years

""
FORMAT( AGE( Birth Date ), "9" ) + " years" 
IF AGE( Birth Date ) < 2 
  FORMAT( MONTHS FROM( Birth Date, TODAY ), "9" ) + " months"  
END IF

Age in years, months, and days as of today

"" 
SET Years TO YEARS FROM( Birth Date, TODAY ) 
SET Months TO MONTHS FROM( Birth Date + Years YEARS, TODAY ) 
SET Days TO DAYS FROM( Birth Date + Years YEARS + Months MONTHS, TODAY )
"«Years» years, «Months» months, and «Days» days"

Age in years, months, weeks, and days as of today

"" 
SET Years TO YEARS FROM( Birth Date, TODAY ) 
SET Months TO MONTHS FROM( Birth Date + Years YEARS, TODAY ) 
SET Weeks TO TRUNCATE( DAYS FROM( Birth Date + Years YEARS + Months MONTHS, TODAY ) / 7, 0 ) 
SET Days TO DAYS FROM( Birth Date + Years YEARS + Months MONTHS + ( Weeks * 7 ) DAYS, TODAY )
"«Years» years, «Months» months, «Weeks» weeks, and «Days» days"