Skip to main content
XMLDir

Search 261 pages — tools, formats, elements, namespaces, XPath, datatypes, glossary, parse errors, schema errors, use cases, blog and product.

XSD datatype

xs:duration

A length of time in ISO 8601 form, starting with P — and only partially ordered, because months have no fixed length.

The form is PnYnMnDTnHnMnS: a leading P, then the date components, then T and the time components. The T is required before any time part, which is why P1M and PT1M mean a month and a minute respectively.

Durations are only partially ordered. P1M and P30D cannot be compared, because a month is 28 to 31 days — so minInclusive on a duration behaves in ways that look broken but are correct.

Lexical space
P, then optional nY nM nD, then optional T with nH nM nS.
Derives from
Primitive type
Category
Date and time types
Facets
minInclusive, maxInclusive, minExclusive, maxExclusive, pattern, enumeration, whiteSpace

What validates

Every literal below is put through the schema validator on each test run, against the schema at the foot of this page.

  • P1Y
  • P1M
  • PT1M
  • P1Y2M3DT4H5M6S
  • -P1D
  • PT0S

What does not

  • 1Y

    The leading P is mandatory.

  • P1H

    Hours are a time component and need the T separator: PT1H.

  • P

    At least one component is required.

  • P1.5Y

    Only the seconds component may be fractional.

What catches people out

  • P1M is one month; PT1M is one minute. The T is the only thing distinguishing them.
  • Durations are partially ordered, so two durations may be incomparable and a range facet may reject something you expected to pass.
  • Only seconds can be fractional. P1.5Y is invalid; PT1.5S is fine.

The schema used

This is the exact schema the literals above are validated against. Paste it into the validator with one of them to see the result yourself.

schema.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="v" type="xs:duration"/>
</xs:schema>

Open the XSD validator

Related

All 29 datatypes and facets

Get started

Bring order to the XML your team can't afford to ignore.

Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.