← All articles

Date math

The Surprisingly Tricky Math of Calculating Someone's Exact Age

Published · 6 min read

“How old are they?” sounds like a one-line question with a one-line answer. It isn’t. Even the most experienced developers regularly trip over the edge cases.

This article walks through the rules a good age calculator must respect — and why calendar arithmetic gets weird if you don’t think about it carefully.

The naive answer

Most people would compute age as:

age = current_year − birth_year

That works for a rough integer answer in conversation, but it’s wrong as soon as the birthday hasn’t happened yet this year. Someone born in November is not one year older the moment the new year arrives.

The correct rule for full years

A person turns N years old on their Nth birthday — meaning the first day of the Nth anniversary year of their birth. The proper rule is:

If today’s month-day is on or after the birth month-day, full years = current year − birth year. Otherwise, full years = current year − birth year − 1.

Already we have a branch. It gets more interesting.

The leap-day exception

What about somebody born on February 29th, 1996? In a non-leap year there is no February 29th. Most jurisdictions consider their “birthday” to be either February 28th or March 1st — but conventions differ:

  • Common law (UK): legal age increases the day before the next anniversary, i.e. February 28th.
  • Civil law (e.g. New Zealand): legal age increases on March 1st.

A general-purpose calculator usually picks March 1st in non-leap years and lets users decide if their jurisdiction differs.

Years, months and days together

Now the really fun part. To express age as “X years, Y months, Z days”:

  1. Compute full years using the rule above.
  2. From the date X years after birth, compute full months remaining up to today.
  3. From the date X years + Y months after birth, compute leftover days up to today.

When you “borrow” a month because the days went negative, you have to use the previous month’s length — which differs depending on which month it was. April has 30 days, March has 31, February has 28 or 29, and so on.

A simpler but slightly less intuitive way is to compute total days and break them into years/months/days afterward. Both approaches must produce the same final breakdown if implemented correctly.

Age across timezones

Age also depends on which timezone you measure in. Someone born at 11pm Sydney time on January 1st was already born in London-time on December 31st — so their birthday “in London” is technically the day before their actual birth.

Our age calculator avoids the issue by performing all arithmetic in UTC, which means it produces the same answer regardless of the device’s timezone. For most everyday purposes the UTC convention is fine; for legal questions, always defer to the relevant jurisdiction’s rules.

Negative age (future dates)

What if you ask “how old will my child be in 2050?” The same arithmetic works — just plug in the future date as the “calculate as of” parameter. Negative ages (i.e. the person hasn’t been born yet) are also defined and useful in genealogy and demographics.

Beyond years

Our age calculator doesn’t stop at years. It also returns:

  • Total days, weeks and hours lived.
  • The exact day of the week of the birth.
  • Western and Chinese zodiac.
  • Birthstone and birth flower.
  • The day-count to the next birthday.

All of that is calculated in your browser — no upload, no third party, no surprises.

TL;DR

  • “How old are they?” is not subtraction.
  • Edge cases include leap years, leap-day birthdays, and negative ages.
  • Always do the math in a single timezone (UTC works well).
  • Always test your code against December 31 → January 1 rollover, February 28/29, and a year that crosses a month boundary.

Tags: age, calendar, leap year


Found this useful? Try a related calculator: browse all date tools →