Parse ISO 8601 duration / time interval string

ISO 8601 durations (intervals) represent a span of time independent of any start or end point. A duration string begins with P (for "period") and lists date components before T and time components after it. Use this tool to calculate total seconds or to find the date and time a duration ago or from now.

Format:  P[nY][nM][nW][nD]T[nH][nM][nS] See below
Examples: PT90S, P1DT12H, P1Y2M3DT4H5M6S or P2W

Enter an ISO 8601 duration string:


 

Convert seconds to ISO 8601 duration

Enter a number of seconds:


 

Duration markers

Marker/LabelMeaningExample
PDuration marker (required prefix)P…
YYearsP2Y — 2 years
M (before T)MonthsP3M — 3 months
WWeeksP2W — 2 weeks
DDaysP10D — 10 days
TTime separator (required before H, M, S)PT…
HHoursPT6H — 6 hours
M (after T)MinutesPT30M — 30 minutes
SSeconds (decimal fractions allowed)PT90S — 90 seconds

Years and months have variable lengths, so conversions involving them use calendar averages (1 year = 365.2425 days, 1 month = 30.436875 days). The W designator for weeks may not be combined with date designators (D, M, Y) in strict ISO 8601, but this tool accepts mixed forms as commonly seen in practice.

ISO 8601 durations are widely used in APIs, XML schemas (xs:duration), iCalendar (RFC 5545), and database types such as PostgreSQL interval and Java’s Duration/Period.

Calculate the difference between two dates