Schema Central > XML Schema 1.0 > xsd:duration
Advanced search
Need XML Help?

Recommended Reading:

Definitive XML Schema

 

Web Service Contract Design and Versioning for SOA

 

Advanced XML Applications

 

xsd:duration

The type xsd:duration represents a duration of time expressed as a number of years, months, days, hours, minutes, and seconds. The format of xsd:duration is PnYnMnDTnHnMnS, where P is a literal value that starts the expression, nY is the number of years followed by a literal Y, nM is the number of months followed by a literal M, nD is the number of days followed by a literal D, T is a literal value that separates the date and time, nH is the number of hours followed by a literal H, nM is the number of minutes followed by a literal M, and nS is the number of seconds followed by a literal S. The following rules apply to xsd:duration values:

  • Any of these numbers and corresponding designators may be absent if they are equal to 0, but at least one number and designator must appear.

  • The numbers may be any unsigned integer, with the exception of the number of seconds, which may be an unsigned decimal number.

  • If a decimal point appears in the number of seconds, there must be at least one digit after the decimal point.

  • A minus sign may appear before the P to specify a negative duration.

  • If no time items (hour, minute, second) are present, the letter T must not appear.

Simple Type Information

Namespace: http://www.w3.org/2001/XMLSchema

Schema Document: datatypes.xsd

Content

Examples

Valid valuesComment
P2Y6M5DT12H35M30S2 years, 6 months, 5 days, 12 hours, 35 minutes, 30 seconds
P1DT2H1 day, 2 hours
P20M20 months (the number of months can be more than 12)
PT20M20 minutes
P0Y20M0D20 months (0 is permitted as a number, but is not required)
P0Y0 years
-P60Dminus 60 days
PT1M30.5S1 minute, 30.5 seconds
Invalid valuesComment
P-20Mthe minus sign must appear first
P20MTno time items are present, so "T" must not be present
P1YM5Dno value is specified for months, so "M" must not be present
P15.5Yonly the seconds can be expressed as a decimal
P1D2H"T" must be present to separate days and hours
1Y2M"P" must always be present
P2M1Yyears must appear before months
Pat least one number and designator are required
PT15.Sat least one digit must follow the decimal point if it appears
an empty value is not valid, unless xsi:nil is used

Type Inheritance Chain

Site developed and hosted by Datypic, Inc.

Please report errors or comments about this site to contrib@functx.com