Home/Date, Time & Scheduling Tools/ISO-8601 Duration String (PnYnMnDTnHnMnS) Math & Interval Combiner

ISO-8601 Duration String (PnYnMnDTnHnMnS) Math & Interval Combiner

Parse, build, combine, and calculate arithmetic intervals for ISO-8601 duration strings (PnYnMnDTnHnMnS) with calendar-aware date anchoring.

Interactive Duration Inputs
Valid
Direct two-way sync: editing this string updates the fields below, and vice versa.
Interval Vector Sign
Date Units (Before 'T')
Time Units (After 'T')
Typical Engineering Presets
Canonical ISO-8601 String
P1Y2M10DT3H30M
Humanized: 1yr 2mo 10d 3h 30m
Approximate Total Equivalents
Total Seconds
37,693,800 s
Baseline calculation
Total Minutes
628,230 min
Exact / 60
Total Hours
10,470.5 hrs
Exact / 3,600
Total Civil Days
436.27 days
Nominal 86,400s per day
Software Implementation Snippets
Temporal: Temporal.Duration.from("P1Y2M10DT3H30M")
Java: Duration.parse("P1Y2M10DT3H30M")

Anatomy of ISO-8601 Duration Strings: The PnYnMnDTnHnMnS Specification

The international standard ISO-8601 defines durations as an amount of intervening time represented in a compact, human-readable, and machine-parsable format. Duration strings adhere to the canonical pattern P[n]Y[n]M[n]D[T[n]H[n]M[n]S], or alternatively P[n]W for whole-week intervals. If you need to measure the exact calendar span between two discrete clock timestamps instead of calculating standardized duration strings, use our elapsed time duration and shift calculator.

Designator 'P'

Period Marker

Every valid duration string begins with P, identifying the payload as an interval rather than a fixed timestamp.

Delimiter 'T'

Time Separator

The capital letter T precedes time units (Hours, Minutes, Seconds). It prevents ambiguity between Months (P1M) and Minutes (PT1M).

Fractional Values

Decimal Precision

The lowest-order component in the string can include a decimal fraction, such as PT0.5S or P1.5Y, utilizing either a point or comma.

ISO-8601 Duration Designators Reference Table

The following matrix outlines each constituent designator, its placement relative to the T separator, and its civil time interpretation:

DesignatorComponentPlacementExampleStandard Notes
PPeriodPrefixP...Mandatory root designator for all duration strings
YYearsDate portionP3YVariable duration (365 or 366 days depending on year)
MMonthsDate portion (pre-T)P6MCalendar-dependent (28, 29, 30, or 31 days)
WWeeksDate portionP2WStandardized as exactly 7 calendar days (604,800 s)
DDaysDate portionP10DStandard civil days (nominally 86,400 seconds)
TTime DesignatorMid-string Delimiter...T...Required before hours, minutes, and seconds
HHoursTime portion (post-T)PT4H3,600 standard SI seconds
MMinutesTime portion (post-T)PT30M60 standard SI seconds
SSecondsTime portion (post-T)PT45.5SFundamental base unit of time measurement

Calendar-Relative Arithmetic vs. Pure Physical Seconds

A frequent pitfall in software engineering is treating duration units as fixed quantities of seconds. While 1 hour = 3600 seconds and 1 minute = 60 seconds are fixed physical truths, date units are variable calendar entities:

Variable Month Lengths & Clamping

A duration of P1M added to January 31 cannot result in "February 31". Modern standards require clamping the day to the last valid day of the target month (February 28 or 29). Adding P1M across summer months (July to August) spans 31 days (2,678,400 seconds), whereas across February it spans only 28 days (2,419,200 seconds).

Daylight Saving Time (DST) Discontinuities

Adding a duration of P1D to a timestamp shifts the calendar date by exactly 1 day (e.g., Sunday 10:00 AM to Monday 10:00 AM), which may encompass 23 or 25 physical hours on DST transition weekends. In contrast, adding PT24H guarantees exactly 86,400 physical seconds, shifting the local time by 1 hour on DST switch dates.

Developer Implementation Guide: JavaScript Temporal, Java, and Python

Modern programming languages have standardized native support for parsing and evaluating ISO-8601 duration strings without third-party regex hacks:

ECMAScript (JavaScript / TypeScript)

JS Temporal API

The modern Temporal.Duration API natively parses and serializes ISO-8601 durations:

const d = Temporal.Duration.from("P1Y2M");
const totalHours = d.total({ unit: "hours", relativeTo: "2026-01-01" });
Java 8+ (java.time)

Period & Duration Classes

Java strictly bifurcates calendar periods from clock-based durations:

Period period = Period.parse("P1Y2M10D");
Duration time = Duration.parse("PT3H30M");
LocalDate target = LocalDate.now().plus(period);
Python (isodate / dateutil)

isodate & relativedelta

Python parses full compound periods through isodate:

import isodate
duration = isodate.parse_duration("P1Y2M10DT3H")
target = datetime.now() + duration

Frequently Asked Questions (FAQ)

What is an ISO-8601 Duration string and what does PnYnMnDTnHnMnS stand for?

An ISO-8601 Duration string represents an exact or calendar-relative span of elapsed time. The format starts with the designator 'P' (for Period). 'Y' denotes Years, 'M' denotes Months, 'W' denotes Weeks, and 'D' denotes Days. The letter 'T' acts as the Time delimiter, separating date components from Hours ('H'), Minutes ('M'), and Seconds ('S'). For instance, P1Y2M10DT3H30M represents 1 year, 2 months, 10 days, 3 hours, and 30 minutes.

Why are Months and Minutes represented by the same letter 'M' in ISO-8601?

Both months and minutes use the capital letter 'M'. They are unambiguously differentiated by the 'T' time designator. Any 'M' appearing before 'T' represents calendar months (e.g., P3M = 3 months), whereas any 'M' appearing after 'T' represents minutes (e.g., PT30M = 30 minutes).

Why does adding a 1-month duration (P1M) result in different elapsed seconds depending on the anchor date?

In ISO-8601 duration arithmetic, months and years are calendar-dependent variable units rather than fixed quantities of seconds. Adding P1M to February 1st elapses 28 days (or 29 in a leap year), while adding P1M to July 1st elapses 31 days. Accurate date math requires evaluating calendar units against a specific base anchor point.

Can an ISO-8601 duration have negative values or represent time subtraction?

Yes. ISO-8601-2 extensions permit leading negative signs (such as -P1D for minus one day) to indicate negative intervals or countdown offsets. In interval algebra and software libraries like Luxon or date-fns, durations can be added or subtracted to roll dates forward or backward.

What is the difference between Weeks (W) and Days (D) in ISO duration strings?

According to the ISO-8601 standard, 'W' is used for week expressions (e.g., P2W = 2 weeks). While strict basic profiles suggest weeks should not be combined with other date units, modern extended ISO profiles permit combining weeks with days and time components. In this tool, 1 week cleanly equates to 7 civil days.

How does this calculator normalize combined interval sequences?

When combining a sequence of intervals (e.g., adding P1Y, subtracting P45D, and adding PT12H), the calculator accumulates both the direct component tallies and the approximate cumulative seconds. The normalized ISO string collapses total seconds back into standard civil calendar units (365-day years, 30-day months, 7-day weeks, 24-hour days, 60-minute hours).

Related & Complementary Utilities

Explore more privacy-first client-side web tools.