XSD Date and Time Data Types
Date and time data types are used to contain values of dates and times.
Date Data Type
The date data type is used to define a date.
A date is defined with the format "YYYY-MM-DD", where:
- YYYY indicates the year
- MM indicates the month
- DD indicates the day
**Note:** All components are required
The following is an example of a date declaration in a schema:
The element in the document should look like this:
Timezone
To specify a time zone, you can also enter a date using Coordinated Universal Time (UTC time) by adding a "Z" after the date - like this:
Or you can specify an offset from UTC by adding a positive or negative time after the date - like this:
or
h2>Time Data Type
The time data type is used to define a time.
A time is defined with the following format: "hh:mm:ss", where
- hh indicates the hour
- mm indicates the minute
- ss indicates the second
Note: All components are required!
The following is an example of a time declaration in a schema:
The element in the document should look like this:
or like this:
Timezone
To specify a time zone, you can also enter a time using Coordinated Universal Time (UTC time) by adding a "Z" after the time - like this:
Or you can specify an offset from UTC by adding a positive or negative time after the time - like this:
or
DateTime Data Type
The datetime data type is used to define a date and a time.
A datetime is defined with 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 portion
- hh indicates the hour
- mm indicates the minute
- ss indicates the second
Note: All components are required!
The following is an example of a datetime declaration in a schema:
The element in the document should look like this:
or like this:
Timezone
To specify a time zone, you can also enter a datetime using Coordinated Universal Time (UTC time) by adding a "Z" after the datetime - like this:
Or you can specify an offset from UTC by adding a positive or negative time after the time - like this:
or
Duration Data Type
The duration data type is used to specify a time interval.
A time interval is specified with the 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 portion (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
The following is an example of a duration declaration in a schema:
The element in the document should look like this:
The example above indicates a period of 5 years.
or like this:
The example above indicates a period of 5 years, 2 months, and 10 days.
or like this:
The example above indicates a period of 5 years, 2 months, 10 days, and 15 hours.
or like this:
The example above indicates a period of 15 hours.
Negative Duration
To specify a negative duration, enter a minus sign before the P:
The example above indicates a period of negative 10 days.
Date and Time Data Types
| Name | Description |
|---|---|
| date | Define a date value |
| dateTime | Define a date and time value |
| duration | Define a time interval |
| gDay | Define a part of a date - day (DD) |
| gMonth | Define a part of a date - month (MM) |
| gMonthDay | Define a part of a date - month and day (MM-DD) |
| gYear | Define a part of a date - year (YYYY) |
| gYearMonth | Define a part of a date - year and month (YYYY-MM) |
| time | Define a time value |
Restriction on Date Data Types
Restrictions that can be used with date data types:
- enumeration
- maxExclusive
- maxInclusive
- minExclusive
- minInclusive
- pattern
- whiteSpace