Name

xs:duration

Facets

xs:enumeration, xs:maxExclusive, xs:maxInclusive, xs:minExclusive, xs:minInclusive, xs:pattern, xs:whiteSpace

The xs:duration datatype is used to represent a period of time. Because periods of time may range from seconds to centuries, it uses a very flexible notation. A duration that includes a year, month, day, hour, minute, and seconds is written as PnYnMnDTnHnMnS, with a possible leading minus sign to indicate negative durations. The number preceding Y is the number of years, the number preceding the first M is months, and the number preceding the D is days. The T separator marks the start of time in the duration; the number preceding H is hours, the number preceding M is minutes, and the number preceding S is seconds and may include a decimal part. The P is always necessary, and the T is necessary if the duration uses units smaller than days. Thus, P2Y is two years. P2M is two months, and PT2M is two minutes. Seven years, four months, six days, thirteen hours, twenty minutes, and four seconds could be written as P7Y4M6DT13H20M4S. Unlike the date and time types, no leading zeros are required.

Comparing durations is difficult, but as long as durations use only year and month or day, hour, minute, and second, it is possible to reliably compare them.

Get XML Pocket Reference, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.