What Is ISO 8601 Duration Format? Reading P1DT2H30M Without Guessing

ISO 8601

An ISO 8601 duration is a length of time written as letters and numbers, without reference to any calendar date. P1DT2H30M means 1 day, 2 hours and 30 minutes. P marks the start of a duration, D means days, T separates the date part from the time part, and H and M mean hours and minutes. If a day is 24 hours, that equals 1,590 minutes. On a day when the clocks change, it does not. Started at 9:00 AM in New York on Saturday, March 13, 2027, P1DT2H30M ends at 11:30 AM on Sunday after 1,530 real minutes. Started at 9:00 AM on Saturday, November 6, 2027, it ends at the same 11:30 AM after 1,650 minutes.

Software that “parses ISO durations” can still produce wrong answers for this reason. The syntax takes a minute to learn. The difficulty is that a duration string mixes two kinds of units. Hours, minutes and seconds have a fixed length. Years, months, weeks and days have a length that depends on the date where you start counting.

How a duration string is built

The format with designators has a fixed order, from the largest unit to the smallest:

ISO 8601 duration, format with designators
PnYnMnWnDTnHnMnS
P = period (required first character)
T = separator, required before any hour, minute or second
Designator Meaning Position Fixed length?
Y Years Before T No: 365 or 366 days
M Months Before T No: 28 to 31 days
W Weeks Before T No in local time: 7 calendar days
D Days Before T No in local time: 23, 24 or 25 hours
H Hours After T Yes: 3,600 seconds
M Minutes After T Yes: 60 seconds
S Seconds After T Yes

The same letter M means months before the T and minutes after it. Because of this, the T is never optional. P5M is five months and PT5M is five minutes. An average month has about 43,829 minutes, so a parser that drops the T is off by a factor of roughly 43,800. Components with a zero value can be left out, but at least one component has to remain. A bare P or PT is invalid. The usual way to write zero is PT0S.

Several other rules are commonly misread:

  • Values do not need to be normalized. PT36H and PT90M are valid strings. A system may convert them to P1DT12H and PT1H30M, but the original form carries information: PT36H says “exactly 36 hours,” while P1DT12H says “one calendar day plus 12 hours.”
  • Only the smallest unit present may have a fraction. PT1.5H and PT0.5S are valid. PT1.5H30M is not, because a fractional hour cannot be followed by minutes. The standard accepts either a comma or a full stop as the decimal sign, so PT0,5S is legal ISO 8601. Many internet formats accept only the full stop.
  • Weeks traditionally stand alone. In the older grammar, also used by the IETF’s RFC 3339 appendix and by iCalendar, the week form is PnW on its own. Java’s documentation says ISO 8601 does not allow PnW to be mixed with PnYnMnD. Some newer systems accept P1W2D anyway: JavaScript’s Temporal keeps it as written, and Java’s Period quietly converts it to P9D.
  • There is a second notation. The “alternative format” writes the same values in date and time shape: P0001-02-03T04:05:06 is one year, two months, three days, 4 hours, 5 minutes and 6 seconds. PostgreSQL accepts both forms.

Reading common duration strings

String Read as Exact length known without a start date?
PT15M 15 minutes Yes: 900 seconds
PT1H30M 1 hour 30 minutes Yes: 5,400 seconds
PT90M 90 minutes (same length as PT1H30M) Yes
PT0.5S Half a second Yes
P1DT2H30M 1 day, 2 hours, 30 minutes No: 1,530, 1,590 or 1,650 minutes depending on the date
P2W 2 weeks No: 14 calendar days, which in a DST zone can be 335, 336 or 337 hours
P1M 1 month No: 28 to 31 days
P1Y 1 year No: 365 or 366 days
P3Y6M4DT12H30M5S 3 years, 6 months, 4 days, 12:30:05 No
-P1D One day backward (extension, not in the basic rules) No

ISO 8601 also defines how dates and times are written, which our guide to the ISO date format covers. Durations are the part of the standard where that guide’s main point, that one string should have one meaning, no longer applies automatically. The string P1M is unambiguous. Its length is not.

Nominal and exact durations: the distinction behind most bugs

The iCalendar standard (RFC 5545, 2009) gives the clearest wording. It calls weeks and days nominal durations and hours, minutes and seconds accurate durations. Months and years are nominal in the same sense, and iCalendar leaves them out of its duration format entirely. A nominal unit is a step on a calendar. An exact unit is a count of elapsed seconds.

What can be computed without a start date
Exact part (seconds) = H × 3,600 + M × 60 + S
Nominal part = Y, M, W, D: needs a start date (and a time zone for D and W)
P1DT2H30M = 1 nominal day + 9,000 exact seconds

The exact part can be converted to seconds and compared with anything. The nominal part has no fixed length until it is placed on a timeline. A duration that contains both kinds, as P1DT2H30M does, therefore cannot be reduced to a single number of minutes without either a start date or an assumption. Most of the problems below happen when a library makes that assumption without telling you.

Why P1M is not 30 days

Months in 2027 have 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30 and 31 days. Their average is 30.42 days, and the average Gregorian month across the 400-year cycle is 30.436875 days (365.2425 ÷ 12). No single fixed value fits every month. A 30-day rule is exactly right for 4 of the 12 months and wrong by one or two days for the other 8.

Adding a month runs into a second problem: some results do not exist. January 31, 2027 plus P1M would be February 31. Temporal in JavaScript, Java’s LocalDate and Python’s isodate library all clamp the result to February 28, 2027 (February 29 in 2028). That convenience has a cost. Adding P1M twice to January 31 gives March 28, while adding P2M once gives March 31, so two one-month steps are not the same as one two-month step. A subscription that renews “one month after the last renewal” falls to the 28th after February and stays there, while one that renews “N months after signup” returns to the 31st whenever the month has one. Temporal can refuse the clamp instead: its overflow: “reject” option throws an error for January 31 plus one month.

Comparison is also affected. The W3C XML Schema 1.1 datatypes recommendation (2012) stores every duration as two numbers, months and seconds, and declares durations only partially ordered. To compare two durations, it adds both to four reference dates: September 1, 1696; February 1, 1697; March 1, 1903; and July 1, 1903. If the results disagree, the durations are “incomparable.” P1M and P30D are one of its examples. Temporal shows the same thing with 2027 dates: from February 1, P1M is shorter than P30D. From March 1 it is longer. From April 1 the two are exactly equal.

An ISO 8601 duration is only a number when it contains hours, minutes and seconds alone; as soon as it contains a day, week, month or year, it is an instruction that needs a start date before it has a length. worldtimedata

Some systems use 30 days anyway, and they document it. PostgreSQL converts fractional months on input assuming 30 days per month and 24 hours per day, so ‘1.75 months’ becomes 1 month 22 days 12:00:00. Whole months are kept as months. That difference matters: the 30-day rule applies only to the fractional part.

P1D vs PT24H on days when the clocks change

In a time zone with daylight saving time, one calendar day per year has 23 hours and another has 25. In 2027 those days are Sunday, March 14 and Sunday, November 7 in the United States, and Sunday, March 28 and Sunday, October 31 in the UK. Adding P1D keeps the clock time. Adding PT24H keeps the elapsed time. We calculated both with the IANA time zone database:

Start (local time) + P1D + PT24H Real hours in P1D
New York, Sat Mar 13, 2027, 9:00 EST Sun Mar 14, 9:00 EDT Sun Mar 14, 10:00 EDT 23
New York, Sat Nov 6, 2027, 9:00 EDT Sun Nov 7, 9:00 EST Sun Nov 7, 8:00 EST 25
London, Sat Mar 27, 2027, 9:00 GMT Sun Mar 28, 9:00 BST Sun Mar 28, 10:00 BST 23
London, Sat Oct 30, 2027, 9:00 BST Sun Oct 31, 9:00 GMT Sun Oct 31, 8:00 GMT 25

Neither result is wrong. They answer different questions. A meeting that is “the same time tomorrow” needs P1D. A token that expires “24 hours after issue” needs PT24H. The error is in using one when the other was meant, which is the same mechanism our article on why scheduled jobs break describes from the scheduler’s side.

Nominal arithmetic can also produce a clock time that does not exist. On March 14, 2027, New York clocks jump from 1:59:59 to 3:00, so 2:30 AM never occurs. Adding P1D to 2:30 AM on March 13 would land in that gap. Temporal’s default “compatible” handling and Java’s ZonedDateTime both move the result forward to 3:30 AM EDT. A system that instead rejects the time, or chooses an earlier offset, will end up a different number of hours later.

The opposite case occurs in November, when 1:30 AM happens twice and a nominal result can match either one. That is the hour that happens twice. A library has to pick one of the two instants: Temporal by default and Java both pick the first, 1:30 AM EDT.

The same string in different software

The ISO grammar is shared, but the data model behind it is not. We ran the same strings through Java 21, the Temporal reference polyfill, Python 3.13 with isodate, and the documented rules of several standards:

System What it stores What P1D means What happens with P1M
Java Duration Seconds and nanoseconds Exactly 24 hours; prints P1DT2H30M as PT26H30M Parse error
Java Period Years, months, days One calendar day Kept as one month; any time part (P1DT2H) is a parse error
JavaScript Temporal.Duration All ten fields as written Calendar day when added to a ZonedDateTime Kept; compare(), total() and round() need relativeTo
Python isodate timedelta, or its own Duration object for Y and M timedelta(days=1), identical to 24 hours Returns a separate Duration type
PostgreSQL interval Months, days, microseconds One calendar day, separate from hours Kept as one month
W3C XML Schema duration Months and seconds 86,400 seconds, the same value as PT24H Kept as one month; only partially ordered
HTML time element Seconds Allowed Not allowed
iCalendar (RFC 5545) Weeks, days, hours, minutes, seconds Nominal day; days are added before hours Not allowed

Two results deserve special attention. No single java.time class can parse P1Y2M3DT4H: Duration rejects the year and month, and Period rejects the hours. Java code that receives arbitrary ISO durations therefore either splits the string or uses a third-party type.

Python’s behavior is subtler. As of Python 3.13, the standard library has no ISO duration parser, and isodate turns P1D and PT24H into the same timedelta. Python then adds a timedelta to a time zone aware datetime by wall clock, not by elapsed time. In our test, 9:00 AM on March 13, 2027 in America/New_York plus PT24H gave 9:00 AM EDT the next day, after only 23 real hours. A Python program that needs PT24H to mean 24 elapsed hours has to convert to UTC, add, and convert back.

The HTML specification gives the reason for excluding months: a month does not have a fixed number of seconds. Its duration format still recognizes the M-before-T syntax for future compatibility, but parsing fails if the month value is not zero. HTML also has a second, non-ISO duration syntax, such as “4h 18m 3s”, which is the only HTML form that allows weeks.

Negative durations and the one-sign rule

The basic rules in ISO 8601-1:2019 describe only positive durations. ISO 8601-2:2019, the extensions part published with it in February 2019, adds a negative duration written with a leading minus sign, with every component inside it positive: -P1DT2H. XML Schema also accepts a leading minus, and iCalendar uses negative durations mainly for alarms that trigger before an event starts.

Signs on individual components are where systems disagree. Java accepts PT-6H3M and reads it as minus 6 hours plus 3 minutes, or 5 hours 57 minutes in the negative direction. Temporal rejects any duration whose fields have mixed signs. PostgreSQL’s own ISO output can produce mixed signs, as in its documented example P-1Y-2M3DT-4H-5M-6S. If you need interchange, use a single leading minus and positive components, because that form is the only one all three of these systems handle.

A February 2025 IETF Internet-Draft by Joe Tsai (draft-tsai-duration-00) proposed going further for internet protocols: allow only hours, minutes and seconds, a full stop as the decimal sign, uppercase letters, a single leading sign, and PT0S as the only zero. Its reasoning was that years, months, weeks and days cannot be turned into a fixed duration without context. It is a draft, not a standard, but the restriction it proposes is a good default for APIs that mean elapsed time.

Where these strings show up

  • Video and media APIs. The YouTube Data API returns contentDetails.duration as an ISO duration, PT#M#S for most videos and P#DT#H#M#S for videos of a day or more. Parsers that only extract the minutes and seconds with a regular expression miss the hours in PT1H2M and the days in P1DT6H11M55S.
  • Recipe and video structured data. Schema.org’s prepTime, cookTime and totalTime properties, which Google reads for recipe search results, use ISO durations such as PT15M and PT1H. A plain “15 min” is not an ISO duration.
  • Calendars and reminders. iCalendar stores event lengths and alarm offsets as durations, P7W or -PT15M for example. Because it has no months, “one month later” has to be expressed with a recurrence rule, not a duration.
  • Databases. PostgreSQL’s interval type keeps months, days and microseconds in separate fields because months vary in length and a day can have 23 or 25 hours, and it can output ISO strings with SET intervalstyle = ‘iso_8601’.
  • Configuration and cloud services. Timeouts, retention periods and retry intervals are often written as PT30S or P7D. Check whether the service treats P7D as 168 hours or as seven calendar days. In UTC-based services there is no difference, but local-time ones differ.

Durations inside intervals and repeating schedules

ISO 8601 also uses durations inside time intervals, separated by a slash: start/end, start/duration, or duration/end. 2027-03-01/P1M is the whole of March 2027, and P1M/2027-03-01 is the month ending on March 1, which is February. Here the nominal unit is no longer ambiguous, because the interval supplies the anchor date.

Repeating intervals add an R prefix. R/2027-01-04T14:00:00Z/P1D repeats daily from 14:00 UTC indefinitely, and R5 limits it to five repetitions. Because this start time is in UTC, the local time moves when the clocks change. In New York, 14:00 UTC is 9:00 AM on March 12, 2027 and 10:00 AM from March 15. In November it is 10:00 AM on November 5 and back to 9:00 AM by November 8. For a schedule that should stay at 9:00 local time, the start must carry a time zone rule, not just a UTC offset. ISO 8601 itself has no notation for an IANA zone name. RFC 9557 (2024) adds one in brackets, such as [America/New_York], and Temporal uses it.

Rules for writing durations that are read correctly

  1. Use only H, M and S for elapsed time. Timeouts, token lifetimes, SLA windows and rate limits should be PT24H, not P1D, and PT720H, not P30D, when the intent is a fixed number of seconds. Such values convert directly to Unix time arithmetic.
  2. Use D, W, M and Y only when calendar steps are meant, and store the anchor with them. “P1M from 2027-01-31 in America/Chicago” is a complete instruction. “P1M” alone is not.
  3. Decide the month-end rule explicitly. Clamping to the last day, rejecting, or always counting from the original date give different results after January 31. Document the choice.
  4. Do not normalize away the meaning. Converting PT36H to P1DT12H turns 36 exact hours into a calendar day plus 12 hours, which differs by an hour on clock change weekends.
  5. Emit one sign, uppercase letters, and a full stop. -PT1H30M and PT0.5S are accepted by more parsers than PT-1H-30M, pt1h30m or PT0,5S, even though the standard itself permits a comma.
  6. Test with the 2027 clock change dates. In the United States, March 14 and November 7. In Europe, March 28 and October 31. Code that returns 1,590 minutes for P1DT2H30M starting at 9:00 AM local time on either Saturday is using a 24-hour day, which may or may not be what you intended.

 


Sources and references

IETF: RFC 3339, Date and Time on the Internet: Timestamps, Appendix A (2002)
ABNF grammar for ISO 8601 durations, including the separate week form and the T separator
W3C: XML Schema Definition Language (XSD) 1.1 Part 2: Datatypes (2012)
Duration as months plus seconds, partial order, four reference dates, P1M and P30D as incomparable
PostgreSQL 18 Documentation: Date/Time Types, Interval Input and Output
ISO 8601 format with designators and alternative format, months/days/microseconds storage, 30-day rule for fractions
↑
✕Close Menu