ISO 8601 Duration Calculator

Read, add and make ISO 8601 durations.

  • Parses P and T parts
  • Month-end rule stated
  • Two dates to P form
A small rounded clay path of stepping stones in graded sizes crossing a clay stream, in soft daylight.

The guide

Why P1M is a month and PT1M is a minute, and what a duration string leaves unsaid

An ISO 8601 duration names an amount of calendar and clock time, not a number of days, so the same string can cover different spans depending on where you start.

  • 59 days P2M from 15 February 2003
  • 62 days P2M from 15 July 2003
  • 129,600 seconds in PT36H
  • 2024-02-29 31 January 2024 plus P1M
  • 2024-03-29 two steps of P1M, not P2M
Read the full guide Fold the guide 6 min · 12 sources

Read P3Y6M4DT12H30M5S aloud and it says three years, six months, four days, twelve hours, thirty minutes and five seconds. Every letter labels the number in front of it. The string is a recipe for an amount of time, written so that a machine and a person can both read it. Nothing in the recipe says how many days that is. The answer depends on the date you start from, and that one fact explains most of the trouble people have with these strings.

What the letters stand for

A duration begins with the capital letter P, for period. Then come the date elements in a fixed order: years with Y, months with M, days with D. The letter T follows, and after it the time elements: hours with H, minutes with M, seconds with S. Weeks have their own form, PnW, where n is the number of weeks.

Two letters appear twice. M before the T means months, and M after the T means minutes. That is the whole reason T exists. The ISO 8601 article resolves the ambiguity this way: P1M is a one-month duration and PT1M is a one-minute duration, and the T that precedes the time value is the signal.

Elements whose value is zero may be left out, so P4Y and P23DT23H are both fine. At least one element must remain, which means a bare P is not a duration. Zero seconds is written PT0S, and P0D means the same thing.

The smallest element you write may carry a decimal fraction, using a dot or a comma. Values may also run past their carry points: PT36H is allowed and means thirty-six hours, the same length as P1DT12H as long as no clock change falls in between. The number of digits allowed in each element is left for the communicating parties to agree, which is why this page caps a number at 12 digits and a fraction at 6.

A duration is not a number of days

Take the article’s own pair of worked intervals. Start at 2003-02-15 and add P2M: the end is 2003-04-15, which is 59 days later. Start at 2003-07-15 and add the same P2M: the end is 2003-09-15, which is 62 days later. The string never changed. February is short, and July and August are long.

So P1M alone could be 28, 29, 30 or 31 days, and P1Y is 365 or 366. The XML Schema datatypes specification goes as far as calling P1M and P31D incomparable: neither is shorter than the other, because the answer depends on the date. The leap year rule is the reason for the year case: a year divisible by four is a leap year unless it is divisible by 100 and not by 400.

Hours, minutes and seconds behave differently. PT36H is 129,600 seconds wherever you start, because 36 times 3,600 is a fixed number. The calendar elements are the slippery ones. A day sits in between. In this page’s arithmetic a day is 24 hours, because there is no time zone. In a place that changes its clocks, a real day can be shorter or longer, and the ISO 8601 article warns that PT36H and P1DT12H are not the same duration when you switch to or from daylight saving time.

Adding months, and finding the gap

If a duration alone has no length, adding it to a date needs a rule, and the durations section of the ISO 8601 article gives the format but no rule for a day that does not exist. The rule here comes from elsewhere. The XML Schema specification states one: add the months first, and if the day is out of range for the new month, pin it to the last day of that month, so that April 31 becomes April 30. Then add the rest.

The dateutil library describes the same behaviour. Adding one month to 2003-01-31 gives 2003-02-28, and adding two months gives 2003-03-31; when the result would fall past the end of the month, the last day is used instead. This page follows that rule, adding years and months first, then days, then the exact time.

Here is the part that surprises people. Add P1M to 2024-01-31 and you land on 2024-02-29, because 2024 is a leap year and February has 29 days. Add P1M again and you reach 2024-03-29. Yet P2M added to 2024-01-31 in one go gives 2024-03-31.

Two steps of P1M are not P2M. The first step lost the day 31 when it was pinned to 29, and nothing in the second step can bring it back. The XML Schema specification says plainly that this kind of addition is not commutative: the order in which you add things matters.

You can reproduce all of this in the tool. Type P1M with the start 2024-01-31 and read the working, then open the month demo and ask for two months. The table lists each step beside the all-at-once answer, and the rows that disagree are marked, so you can see on which month the day was lost and that no later step recovers it. Subtraction is the same rule run with the sign reversed: take P1M from 2024-03-31 and the day is pinned to 29, giving 2024-02-29, which is why the tool never claims that adding and then subtracting returns you to the start.

To turn two dates into a duration, invert the recipe. Find the greatest whole number of months that does not pass the end date, then count the whole days left, then the time of day left. From 2024-01-31 to 2024-02-29 the gap is P1M. From 2023-01-31 to 2023-03-01 it is P1M1D, since a month fits (to 2023-02-28) and one day remains.

A gap is only right if adding it back to the start lands exactly on the end. The tool runs that test on every gap it shows. Its self-check repeats it for 20,000 seeded pairs against a separate model built from the platform Date, which has to set years explicitly because Date.UTC reads the years 0 to 99 as 1900 to 1999. The check runs in a web worker, a background thread, so the page stays responsive.

Where durations appear

Calendar files use them wherever a property holds a duration of time. The iCalendar format, defined in RFC 5545, writes one as P followed by days, a time part or a number of weeks. It does not support the Y and M designators, because it represents nominal durations in weeks and days and accurate durations in hours, minutes and seconds. A duration of seven weeks is P7W, and a duration of 15 days, 5 hours and 20 seconds is P15DT5H0M20S.

The same text notes that a negative duration is typically used to schedule an alarm before an event. It also says leap seconds must not be counted when computing an exact duration, which matches the rule used here. Media and schedules use the notation too. Schema.org lists a duration property for movies, audio recordings, events and schedules, asks for it in this format, and uses the same type for the time a recipe takes to cook.

Date libraries have to make the same choices. Python’s datetime module treats every day as exactly 86,400 seconds, with no notion of leap seconds, and it stops at the years 1 and 9999. This tool keeps those limits, and it counts its results in whole microseconds, so a fraction such as PT0.5S stays exact. Large counts on the page are formatted with the browser’s language-sensitive number formatting.

What this does not do

Two things the page refuses are worth stating. It takes no time zone, so it cannot tell you what a duration does across a daylight saving change. And it will not read a fraction of a year or month, because the standard leaves the length of such a fraction to the parties who exchange the data.

Leap seconds are out as well. A UTC day can hold 86,401 seconds, but a wall-clock model of the kind used here cannot represent the 60th second, so the tool refuses one in a date and treats every minute as 60 seconds. The proleptic Gregorian calendar, the Gregorian rules extended to years before its introduction, is used for every date from 0001 to 9999.

Repeating intervals, signs and the form that mixes weeks with other elements are not read either. The article’s text shows the week form only on its own, so the tool reads it only that way and says that other readers may differ.

The sum of all this is a modest rule of thumb. A duration is a statement about calendar and clock units, and it becomes a length of time only when it is anchored to a date. Write the anchor down, state how the month end is handled, and the ambiguity disappears.

Sources

Every source consulted for this guide. Links checked November 10, 2026.

  1. ISO 8601 Wikipedia (CC BY-SA)
  2. Leap year Wikipedia (CC BY-SA)
  3. Proleptic Gregorian calendar Wikipedia (CC BY-SA)
  4. Leap second Wikipedia (CC BY-SA)
  5. Internet Calendaring and Scheduling Core Object Specification (iCalendar), RFC 5545 IETF (B. Desruisseaux, editor)
  6. W3C XML Schema Definition Language (XSD) 1.1 Part 2: Datatypes W3C
  7. relativedelta dateutil documentation (Apache 2.0 or BSD licence)
  8. datetime - Basic date and time types Python Software Foundation, Python documentation (PSF License)
  9. Duration Schema.org (CC BY-SA)
  10. Date.UTC() MDN Web Docs (CC BY-SA)
  11. Web Workers API MDN Web Docs (CC BY-SA)
  12. Intl.NumberFormat MDN Web Docs (CC BY-SA)