Developer and Text Tools

ISO 8601 Durations Explained: P, T and Month-End Surprises

Learn to read and write ISO 8601 durations like PT1H30M and P1Y2M, convert them to seconds, add them to dates correctly and avoid the month-end trap.

Saizul Amin
Saizul Amin3 Nov 2026 · 4 min read
ISO 8601 Durations Explained: P, T and Month-End Surprises

ISO 8601 Durations Explained: P, T and Month-End Surprises

Strings like PT15M and P1Y2M10DT2H30M show up in video metadata, cloud APIs, XML documents, calendar files and healthcare messages. They are compact and unambiguous once you know the rules, yet small slips, such as PT1M versus P1M, cause real bugs. This guide explains the format and how to check your work with the free ISO 8601 Duration Calculator.

Reading the letters

Every duration starts with P for period. Then come the date parts:

  • Y for years
  • M for months
  • W for weeks
  • D for days

If there are hours, minutes or seconds, a T comes next, followed by:

  • H for hours
  • M for minutes
  • S for seconds

So M means months before the T and minutes after it. PT1M is one minute, P1M is one month, and P1MT1M is one month and one minute. Each part is optional, but the string must contain at least one, and a lone T with nothing after it is invalid.

Only the last, smallest part may have a fraction: PT1.5H and PT0.25S are fine, PT1.5H30M is not. Some systems also accept a leading minus sign for negative durations, such as -PT15M, although the original standard has no sign.

Fixed and flexible units

Seconds, minutes and hours always have the same length. Days and weeks are fixed too if you work in UTC. Months and years are not: a month can have 28 to 31 days, a year 365 or 366. That is why the question "how many seconds is P1M?" has no single answer.

The calculator gives two kinds of answers. For a nominal total it uses the average Gregorian year of 365.2425 days and an average month of a twelfth of that, and it labels the result as nominal. For an exact answer, use the add tab and apply the duration to a real start date.

Adding a duration to a date

The order of operations matters. The calculator follows the approach used by most date libraries:

  1. Add years and months while keeping the day of the month.
  2. If that day does not exist in the target month, clip it to the last day.
  3. Add weeks and days.
  4. Add hours, minutes and seconds.

The clipping rule causes the classic surprise: 31 January plus P1M becomes 28 February, and adding P1M again gives 28 March, not 31 March. If you need "last day of every month", compute it as a rule rather than by repeatedly adding a month. The repeat field in the tool shows exactly what a naive loop would produce, which is a good way to test your own scheduling code.

The duration between two dates

Going the other way, from two date-times to a duration, also needs a convention. The calculator counts whole calendar months first, then leftover days and time, and checks that the start plus the result lands exactly on the end. It also prints plain totals in days, hours and seconds, which are often what a report actually needs.

Normalising

PT90M and PT1H30M are equal, and both are valid. Normalising rewrites a duration into its tidiest form by carrying seconds into minutes and minutes into hours. You can choose whether to carry hours into days as well; leave that off when you work in local time, because a calendar day across a daylight-saving change is 23 or 25 hours long.

Working with lists

The batch tab accepts one duration per line, for example the lengths of videos returned by a video platform's API, task estimates or sensor intervals. Each line is checked, converted to seconds and described in words, and the list is summed. Invalid lines are flagged instead of breaking the whole job, and everything exports to CSV.

Weeks with other units

Combining weeks with other units, such as P1W2D, is allowed by the 2019 edition of ISO 8601 but was not allowed earlier, and some parsers still reject it. If your target system is strict, write P9D instead. The calculator warns when it sees this combination.

Quick reference

  • PT30S: 30 seconds
  • PT45M: 45 minutes
  • PT1H30M: 1.5 hours
  • P1D: one day
  • P2W: two weeks
  • P1Y6M: one and a half years
  • P3Y6M4DT12H30M5S: the classic textbook example

With the letters and the month-end rule in mind, ISO 8601 durations stop being cryptic and become one of the clearer formats in a developer's toolbox.

Completely freeNo cost, no sign-up
Files stay privateEverything runs in your browser
Easy in your languageAvailable in many languages