Counting dates: days between dates, leap years and ISO weeks

Updated:

Counting dates sounds like simple arithmetic, until a deadline comes out a day short, a monthly payment lands on the wrong day or Excel insists that 29 February 1900 existed. The calendar is irregular: months have four different lengths, some years have an extra day, weeks do not fit neatly into years, and in many countries, on two days a year the clock skips or repeats an hour. This guide covers how to count days, leap years and week numbers, and how to write a date so that nobody misreads it.

Counting the days between two dates

The number of days between two dates is the later one minus the earlier one. From 1 March to 10 March is 9 days: you count the days that pass, so one end is left out — just as from Monday to Tuesday is one day. If both the first and the last day count — the days of a festival, or the days of leave you take — add one, and the answer is 10. Both answers are right; they count different things, so decide which one you need before you start.

Legal deadlines follow rules set by law. In the European Union, Regulation (EEC, Euratom) No 1182/71 sets the default rules for time limits in acts of the Council and the Commission: when a period runs from an event, the day of the event is not counted, a period in days ends at the end of its last day, and if that day is a Saturday, Sunday or public holiday the period runs to the end of the next working day. National laws, contracts and courts may count differently, so for a real deadline check the rule that applies to it.

A year has 365 days, or 366 when it is a leap year. From 1 January 2026 to 1 January 2027 is 365 days; from 1 January 2028 to 1 January 2029 is 366, because 2028 is a leap year.

Time since a date

A day is not always 24 hours

Where clocks change for daylight saving time, one day a year has 23 hours and another has 25. In the European Union, where the clocks change on the last Sundays of March and October (see the first part of this series), in 2026 those days are 29 March and 25 October. So from 1 March to 1 April 2026 in Lisbon there are 31 calendar days, but only 743 hours, not 744.

That is why multiplying days by 24, or dividing hours by 24, gives wrong answers across a clock change. The Time since a date tool counts days on the calendar and hours as time actually elapsed, so in Between two dates mode, on a device set to Lisbon time, it shows 31 days and 743 hours for that period. When the time of day matters, as with a meeting or a flight, convert with the time zone, not with a fixed number of hours.

Leap years

A leap year adds 29 February to keep the calendar in step with the seasons. The rule of the Gregorian calendar, as the US Naval Observatory puts it: every year exactly divisible by four is a leap year, except years exactly divisible by 100, which are leap years only if they are also divisible by 400. So 2000 was a leap year, 1900 was not, and 2100 will not be.

Over a 400-year cycle that gives 97 leap days, an average year of 365.2425 days. The Gregorian calendar was introduced in 1582, when 4 October was followed directly by 15 October, but countries adopted it at different times: Britain and its colonies switched in 1752, when 2 September was followed by 14 September. Dates before a country's switch may have been written in the older Julian calendar, so historical dates need checking against the calendar in use at the time.

Excel has a famous exception. Microsoft states that Excel incorrectly treats 1900 as a leap year, a choice made for compatibility with Lotus 1-2-3, and that its WEEKDAY function returns wrong values for dates before 1 March 1900. From 1 March 1900 onwards, it makes no difference.

YearLeap year?Why
2024YesDivisible by 4.
2026NoNot divisible by 4.
2028YesDivisible by 4.
1900NoDivisible by 100 but not by 400.
2000YesDivisible by 400.
2100NoDivisible by 100 but not by 400.

Months have different lengths

Adding a month is trickier than it looks, because the same day does not exist in every month. One month after 31 January has no obvious answer, because February has no 31st. Different systems choose differently. In JavaScript, setting a 31 January 2026 date to February overflows into March and gives 3 March 2026. The EU regulation on time limits takes the other approach: when a period in months or years should end on a day that does not exist in the last month, it ends at the end of that month's last day — 28 February in 2026, or 29 February in a leap year.

When the day of the month matters, as with a rent or subscription due on the 31st, agree in advance what happens in shorter months. Counting in days avoids the problem altogether, at the cost of the date drifting from month to month.

Birthdays on 29 February

Someone born on 29 February has a birthday on the calendar only in leap years, and every age calculation has to decide what happens in the other years. The Age calculator treats 1 March as the birthday in common years: the age goes up on 1 March, and that is the date it shows as the next birthday.

The law differs from country to country, and many laws do not say. The Age of Legal Capacity (Scotland) Act 1991, for example, states that a person born on 29 February reaches a given age on 1 March. For a legal age, such as for a contract or a pension, check the rule in the country concerned.

Age calculator

ISO week numbers

The international standard for week numbers is ISO 8601: weeks start on Monday, and week 1 is the week that contains the year's first Thursday — which is the same as the week that contains 4 January. A year therefore has 52 or 53 weeks.

Near 1 January the week-numbering year can differ from the calendar year. 1 January 2026 is a Thursday, so week 1 of 2026 runs from Monday 29 December 2025 to Sunday 4 January 2026. 2026 has 53 weeks, because it starts on a Thursday, and 1 to 3 January 2027 belong to its week 53. Other conventions exist, some starting weeks on Sunday or counting the week that contains 1 January as week 1, so the same date can have different week numbers in different software; check which system a calendar uses before comparing.

DateWeekdayISO week
29 December 2025Monday2026-W01
1 January 2026Thursday2026-W01
31 December 2026Thursday2026-W53
1 January 2027Friday2026-W53
4 January 2027Monday2027-W01
1 January 2028Saturday2027-W52

Writing dates: YYYY-MM-DD

07/10/2026 means 7 October in the United Kingdom, France, Portugal, Brazil and most other countries that put the day first, but 10 July in the United States. The ISO 8601 calendar date avoids the doubt by putting the largest unit first: 2026-10-07, with a four-digit year and two-digit month and day.

Written that way, dates also sort correctly as plain text. RFC 3339, the internet profile of ISO 8601, points out that ordering the components from the least to the most precise makes date strings sortable as text, as long as they all use the same format. That is why file names and spreadsheet exports that begin with 2026-10-07 line up in date order on their own. The first part of this series covers the time of day, UTC offsets and time zones.

Frequently asked questions

How many days are there between two dates?

Subtract the earlier date from the later one: from 1 to 10 March is 9 days. If you need to count both the first and the last day, add one.

Why is 2100 not a leap year?

Years divisible by 100 are leap years only if they are also divisible by 400. 2000 was, 2100 is not, and the next century leap year after 2000 is 2400.

Which week is 1 January in?

It depends on the weekday. On a Monday to Thursday it is in week 1 of the new year; on a Friday to Sunday it belongs to the last week of the previous year, as 1 January 2027 belongs to week 53 of 2026.

Why does Excel accept 29 February 1900?

Excel treats 1900 as a leap year for compatibility with Lotus 1-2-3, as Microsoft documents. 1900 was not a leap year; the error only affects dates before 1 March 1900.

When does someone born on 29 February have a birthday?

On 29 February in leap years. In other years it is a matter of convention or law: the Age calculator uses 1 March, as Scottish law does, but rules for legal age differ between countries.

Previous in the series ← Unix timestamps and time zones explained

References

  1. US Naval Observatory — Leap Years
  2. US Naval Observatory — Introduction to Calendars
  3. Calendar (New Style) Act 1750
  4. Regulation (EEC, Euratom) No 1182/71 determining the rules applicable to periods, dates and time limits (1971)
  5. Directive 2000/84/EC on summer-time arrangements (2001)
  6. Microsoft Learn — Excel incorrectly assumes that the year 1900 is a leap year
  7. Microsoft Learn — DATEPART (Transact-SQL): week and ISO week
  8. MDN Web Docs — Date.prototype.setMonth()
  9. Age of Legal Capacity (Scotland) Act 1991, section 6
  10. WHATWG HTML Standard — Weeks
  11. ISO — ISO 8601 Date and time format
  12. RFC 3339 — Date and Time on the Internet: Timestamps (July 2002)

Related guides