Demos

Enter a date of birth. "Measured on" starts on today.

Usage

Use the age calculator wherever a result depends on age, such as a growth chart or a reference range. It shows three ages:

  • Chronological — Months since birth, in WHO months of 30.4375 days. From 24 months it shows years and months, such as 3 y 2 mo.
  • Corrected — Chronological age less the weeks born before term (40 weeks). Never below zero.
  • Completed years — Age as a birthday counts it. Someone born on 29 February has their birthday on 1 March in other years.

Import it from @workspace/ui/tools/age-calculator.

Notes

  • Growth charts use corrected age for babies born before 37 weeks, usually until 24 months. For a baby born at term, leave "Born at" on 40 and both ages match.
  • "Born at" takes 22 to 42 weeks. Clearing it goes back to 40. Over 40 weeks makes no correction.
  • Dates are read as UTC midnight, so the result is the same in every time zone.
  • The reset button goes back to the default dates and weeks.

Age helpers

The maths is in @workspace/ui/lib/age, so you can use it without the UI.

calculateAge(birth, measured, gestationalWeeks) from the component file returns all three at once, or null when the measurement date is before the date of birth.

Examples

Born early

A baby born at 32 weeks, measured at 11 months. Eight weeks come off, so the corrected age is 9.5 months.

Listen for changes

Pass onChange to get the result each time an input changes. You get null when no result can be worked out.

Props

Unlisted props pass through to the Card that wraps the calculator.

AgeCalculator

PropTypeDefaultDescription
defaultBirthDateDate—Date of birth on first render and after reset.
defaultMeasuredDateDatetodayMeasurement date on first render and after reset.
defaultGestationalWeeksnumber40Weeks of pregnancy at birth.
onChange(result: AgeResult or null) => void—Called when the result changes.
classNamestring—Classes merged onto the card.

AgeResult

FieldTypeDescription
ageMonthsnumberChronological age in WHO months.
correctedAgeMonthsnumberAge in months corrected for prematurity.
completedYearsnumberCompleted years.

Pass any month value to formatAge to show it as text.