<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Outfit:wght@600;700;800&family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap">
⚡ Productivity guide

How to Calculate Exact Age and Date Differences: Leap Years, Month Ends, Time Zones

Calculate age in years, months and days, handle 29 February birthdays and month-end dates, and avoid date bugs in JavaScript and Python.

📅 Published 2026-11-15⏱️ 5 min read🛠️ 4 free tools

Working out someone’s age seems trivial until a form asks for it in years, months and days as on a cut-off date, or a birthday falls on 29 February, or your code says a user turned 18 a day early. Calendar arithmetic is irregular: months have 28 to 31 days, years have 365 or 366, and "one month after 31 January" has no obviously correct answer.

This guide explains how exact age is calculated, the edge cases that produce different answers from different tools, how to count days between dates, and how to do it reliably in JavaScript and Python. For working with raw timestamps, see the guide on Unix timestamps.

The years, months and days method

The usual method subtracts each part separately, working from days up, and borrows when a part goes negative. If the days are negative, borrow a month and add the number of days in the month before the end date. If the months are negative, borrow a year and add 12.

The result reads naturally: "25 years, 2 months and 15 days" means that adding 25 years and 2 months to the birth date lands on 31 October 2026, and 15 more days reaches 15 November.

Born 31 Aug 2001, age on 15 Nov 2026

            Year   Month   Day
End         2026     11     15
Start       2001      8     31
Raw diff      25      3    −16

Days negative → borrow 1 month, add days in October (31):
              25      2     15

Age: 25 years, 2 months, 15 days

Month ends: where tools disagree

The borrow method breaks down when the start day does not exist in the borrowed month. From 31 January to 1 March 2025, borrowing February’s 28 days gives 1 − 31 + 28 = −3 days, which is not a valid answer. Libraries resolve this in different ways:

  • Clamp to the month end: 31 January plus one month is 28 February (29 in a leap year), and one more day reaches 1 March, giving 1 month and 1 day. Python’s dateutil, the JavaScript Temporal API and most spreadsheet functions behave like this.
  • Borrow from the start month instead: 1 − 31 + 31 = 1 day, again 1 month and 1 day, which agrees in this case but not in all.
  • Overflow: JavaScript’s Date treats "31 February" as 3 March (or 2 March in a leap year), so naive date arithmetic can skip past the end of a short month.
  • For forms and contracts, the counting rule in the document wins. If you build a calculator, pick one rule, document it, and test 29, 30 and 31 day-of-month birthdays against February.

Leap-day birthdays

Someone born on 29 February 2004 has a calendar birthday only in leap years. In other years, is their birthday 28 February or 1 March? Both conventions exist, and laws differ between countries and between purposes such as driving licences, voting and contracts. If an age threshold matters legally, check the rule that applies rather than relying on a library default.

Libraries differ too. Adding 18 years to 29 February 2004 gives 28 February 2022 in Python’s dateutil and in Temporal (both clamp), while the simple year-month-day comparison shown in the code below treats the birthday as 1 March, because 28 February is still "before" 29 February. Decide which you want and write a test for it.

Counting days: inclusive or exclusive

The difference between two dates is exclusive by default: from 1 January to 10 January is 9 days. That is right for "how long ago" or "how many nights". Leave applications, rental periods and some legal deadlines count both the first and last day, which gives 10. Neither is wrong; they answer different questions, and an off-by-one error here is one of the most common bugs in date code.

Age is a special case of the same question. Most systems treat the date of birth as day zero, so a baby is 0 days old on the day they are born. A few official forms count the birth date as day one; follow the form.

Time zones and "turning 18 today"

Age changes at midnight in the person’s local time, not in UTC. A server running in UTC that checks whether a user in India is 18 will be wrong between midnight and 5:30 in the morning IST on their birthday, because the server still thinks it is the previous day. A user in California is affected for eight hours in the other direction.

Treat a date of birth as a plain calendar date, not a timestamp. Store it as YYYY-MM-DD with no time and no zone, compute "today" in the user’s time zone (or the jurisdiction whose rule applies), and compare dates, not instants. Converting a birth date to midnight UTC and back is how a 15 March birthday turns into 14 March on a screen in New York.

Date maths in code

In JavaScript, new Date(’2004-02-29’) is parsed as midnight UTC, so in any time zone west of UTC it displays as 28 February. Months in the Date constructor are zero-based, and out-of-range values silently roll over: new Date(2026, 1, 30) is 2 March 2026. For day differences, use Date.UTC so daylight-saving changes do not produce 23- or 25-hour days.

The Temporal API fixes most of this with PlainDate, a date without a time or zone, and is now shipping in major browsers; use the polyfill where it is not yet available. In Python, the standard datetime.date type has no time zone, and dateutil.relativedelta returns years, months and days directly.

// JavaScript: whole years, comparing calendar dates as strings
function ageOn(birth, on) {            // 'YYYY-MM-DD'
  const [by, bm, bd] = birth.split('-').map(Number);
  const [y, m, d] = on.split('-').map(Number);
  let age = y - by;
  if (m < bm || (m === bm && d < bd)) age--;
  return age;
}
ageOn('2001-08-31', '2026-11-15');     // 25

// Days between two dates, unaffected by DST
const days = (Date.UTC(2026, 10, 15) - Date.UTC(2026, 0, 1)) / 86400000; // 318

// Temporal: years, months and days
const birth = Temporal.PlainDate.from('2001-08-31');
const diff = birth.until(Temporal.PlainDate.from('2026-11-15'), { largestUnit: 'years' });
// diff.years 25, diff.months 2, diff.days 15

# Python
from datetime import date
from dateutil.relativedelta import relativedelta
rd = relativedelta(date(2026, 11, 15), date(2001, 8, 31))
print(rd.years, rd.months, rd.days)   # 25 2 15

Quick checks

To get your exact age today in years, months and days, enter your date of birth in the Neemtools Age Calculator; it reads the date in your own time zone. When the dates come from logs or an API as Unix timestamps, convert them with the Epoch Time Converter first, check which calendar date each one falls on in the relevant time zone, and only then do the date arithmetic.

More guides you might like

Ready to try it?

Open the free All Calculators and apply what you just read. No sign-up, nothing uploaded.

Open All Calculators →

← All guides