Pregnancy apps often say "you are 9 days pregnant" when conception happened only a week ago, or hasn't happened yet. The reason is a convention every developer touching this kind of data should know: gestational age is counted from the first day of the last menstrual period (LMP), not from conception.
This post walks through the date math, the pitfalls, and a small JavaScript snippet. If you want the plain-language side, here is 9 days pregnant explained.
Everything here is an estimate for learning purposes. It is not medical advice. Only a healthcare professional can tell you about a real pregnancy.
Why LMP and not conception?
Most people know the date their last period started. Almost nobody knows the exact day of ovulation or conception. So the standard is to use a date that is easy to record. Conception is assumed to happen about two weeks after LMP, which means "day 9" is counted from the period start, before ovulation would typically occur.
The two formulas
- Gestational age = today - LMP, in days. Divide by 7 for weeks plus remaining days.
- Estimated due date (Naegele's rule) = LMP + 280 days (40 weeks).
Naegele's rule assumes a 28-day cycle. Real cycles vary, so the result is only an estimate.
The pitfalls
Timezones. new Date("2026-12-06") is parsed as UTC midnight, while new Date(2026, 11, 6) is local midnight. Subtracting them can leave you a day off, depending on where the user is.
Daylight saving time. Some days have 23 or 25 hours. If you divide milliseconds by 86,400,000 and call Math.floor, you can lose a day around DST changes.
Off-by-one. Is the LMP day itself day 0 or day 1? Pick one convention and document it. The code below treats the LMP as day 0.
A small JavaScript snippet
The trick is to do the math in UTC calendar days, so local time and DST don't matter:
const MS_PER_DAY = 86_400_000; // Convert a "YYYY-MM-DD" string to a UTC day number function toDayNumber(isoDate) { const [y, m, d] = isoDate.split("-").map(Number); return Date.UTC(y, m - 1, d) / MS_PER_DAY; } function gestationalAge(lmp, today) { const days = toDayNumber(today) - toDayNumber(lmp); return { days, weeks: Math.floor(days / 7), remainder: days % 7 }; } function dueDate(lmp) { const ms = (toDayNumber(lmp) + 280) * MS_PER_DAY; return new Date(ms).toISOString().slice(0, 10); } console.log(gestationalAge("2026-11-27", "2026-12-06")); // { days: 9, weeks: 1, remainder: 2 } console.log(dueDate("2026-11-27")); // 2027-09-03 Because both dates are plain calendar dates converted with Date.UTC, every day is exactly 86,400,000 ms and the result is stable in any timezone.
Testing tips
- Test LMP and today being the same day (expect 0).
- Test a range that crosses a DST change.
- Test a leap year, such as an LMP in 2027 with a due date in 2028.
- Run the tests with a different
TZenvironment variable.
Wrap up
LMP-based counting is just date subtraction, but the details (UTC, DST, day 0 vs day 1) are where bugs hide. Treat the output as an estimate, show that clearly in your UI, and never present it as medical advice.