XSD Date and TimeData Types


Date and time data types are used to contain date and time values.


Date Data Type

The date data type is used to define a date.

The date is defined using this format: "YYYY-MM-DD", where:

  • YYYY indicates the year
  • MM indicates the month
  • DD indicates the day

Note:All components are required.

Below is an example of a date declaration in a schema:

<xs:element name="start" type="xs:date"/>

The element in the document should look like this:

<start>2002-09-24</start>

Timezone

To specify a timezone, you can also enter a date using Coordinated Universal Time (UTC time) by adding a "Z" after the date - like this:

<start>2002-09-24Z</start>

Alternatively, you can specify an offset from UTC by adding a positive or negative time after the date - like this:

<start>2002-09-24-06:00</start>

or

<start>2002-09-24+06:00</start>


h2>Time Data Type

The time data type is used to define a time.

Time is defined using the following format: "hh:mm:ss", where

  • hh indicates the hour
  • mm indicates the minute
  • ss indicates the second

Note:All components are required!

Below is an example of a time declaration in a schema:

<xs:element name="start" type="xs:time"/>

The element in the document should look like this:

<start>09:00:00</start>

or like this:

<start>09:30:10.5</start>

Timezone

To specify a timezone, you can also enter a time using Coordinated Universal Time (UTC time) by adding a "Z" after the time - like this:

<start>09:30:10Z</start>

Alternatively, you can specify an offset from UTC by adding a positive or negative time after the time - like this:

<start>09:30:10-06:00</start>

or

<start>09:30:10+06:00</start>


DateTime Data Type

The dateTime data type is used to define a date and time.

The dateTime is defined using the following format: "YYYY-MM-DDThh:mm:ss", where:

  • YYYY indicates the year
  • MM indicates the month
  • DD indicates the day
  • T indicates the start of the required time section
  • hh indicates the hour
  • mm indicates the minute
  • ss indicates the second

Note:All components are required!

Below is an example of a dateTime declaration in a schema:

<xs:element name="startdate" type="xs:dateTime"/>

The element in the document should look like this:

<startdate>2002-05-30T09:00:00</startdate>

or like this:

<startdate>2002-05-30T09:30:10.5</startdate>

Timezone

To specify a timezone, you can also enter a dateTime using Coordinated Universal Time (UTC time) by adding a "Z" after the dateTime - like this:

<startdate>2002-05-30T09:30:10Z</startdate>

Alternatively, you can specify an offset from UTC by adding a positive or negative time after the time - like this:

<startdate>2002-05-30T09:30:10-06:00</startdate>

or

<startdate>2002-05-30T09:30:10+06:00</startdate>


Duration Data Type

The duration data type is used to specify time intervals.

Time intervals are specified using the following format: "PnYnMnDTnHnMnS", where:

  • P indicates the period (required)
  • nY indicates the number of years
  • nM indicates the number of months
  • nD indicates the number of days
  • T indicates the start of the time section (this is required if you intend to specify hours, minutes, and seconds)
  • nH indicates the number of hours
  • nM indicates the number of minutes
  • nS indicates the number of seconds

Below is an example of a duration declaration in a schema:

<xs:element name="period" type="xs:duration"/>

The element in the document should look like this:

<period>P5Y</period>

The example above represents a period of 5 years.

or like this:

<period>P5Y2M10D</period>

The example above represents a period of 5 years, 2 months, and 10 days.

or like this:

<period>P5Y2M10DT15H</period>

The example above represents a period of 5 years, 2 months, 10 days, and 15 hours.

or like this:

<period>PT15H</period>

The example above represents a period of 15 hours.

Negative Duration

To specify a negative duration, enter a minus sign before the P:

<period>-P10D</period>

The example above represents a period of negative 10 days.


Date and Time Data Types

Name Description
date Defines a date value
dateTime Defines a date and time value
duration Defines a time interval
gDay Defines a part of a date - day (DD)
gMonth Defines a part of a date - month (MM)
gMonthDay Defines a part of a date - month and day (MM-DD)
gYear Defines a part of a date - year (YYYY)
gYearMonth Defines a part of a date - year and month (YYYY-MM)
time Defines a time value


Restrictions on Date Data Types

Restrictions that can be used with the date data type:

  • enumeration
  • maxExclusive
  • maxInclusive
  • minExclusive
  • minInclusive
  • pattern
  • whiteSpace
Other extensions