top of page

79. Age in Years, Months and Days

Description

Calculates an individual's age in years, months and days.

Code

// First the years
SET Temp-n TO YEARS FROM( BirthDate-d , TODAY )
"«Temp-n» year"
IF Temp-n != 1
RESULT + "s"
END IF

// Now the months
SET Temp-n TO MONTHS FROM(
BirthDate-d + Temp-n YEARS,
TODAY )
RESULT + ," «Temp-n» month"
IF Temp-n != 1
RESULT + "s"
END IF

// And finally days
SET Temp-n TO DAYS FROM(
BirthDate-d
+ YEARS FROM( BirthDate-d , TODAY ) YEARS
+ Temp-n MONTHS ,
TODAY )
RESULT + " and «Temp-n» day"
IF Temp-n != 1
RESULT + "s"
END IF


Explanation
This computation computes age based on a birth date (BirthDate-d) and a reference date ("TODAY" in the computation) and returns the computed age in a formatted text string: "X years, Y months and Z days."

The computation uses three variables: BirthDate-d, a date variable, "TODAY" (or another date variable) as the reference date, and Temp-n, a temporary number variable (which should be set to "Ask only in dialog," "Don't warn if unanswered," and "Don't save in answer file" under the Advanced options).

Code
SET NumYears-n TO YEARS FROM( BirthDate-d, EndDate-d )
SET NumMonths TO MONTHS FROM(
BirthDate-d + NumYears-n YEARS,
EndDate-d
)
SET NumDays TO DAYS FROM (
BirthDate-d + NumYears-n YEARS + NumMonths MONTHS,
EndDate-d
)

Explanation

This computation uses the same logic as the above computation (and was, in fact, the source for much of its logic), but instead of returning a formatted string it places the Year, Month, and Days values into three number variables: NumYears-n, NumMonths, and NumDays. These variables can then be referenced individually as needed in the document.

bottom of page