XSD Date and Time
Data Types
Date and time data types are used to include date and time values.
Date Data Type
The date data type is used to define a date.
A date is defined using this format: "YYYY-MM-DD", where:
- YYYY represents the year
- MM represents the month
- DD represents the day
Note: All components are required.
Below is an example of a date declaration in a schema:
The element in the document should look like this:
Time Zone
If you need to specify a time zone, you can also input a date using Coordinated Universal Time (UTC) by appending a "Z" to the date, like this:
Or you can specify an offset from Coordinated Universal Time by appending a positive or negative time to the date, like this:
The time data type is used to define a time.
A time is defined using the following format: "hh:mm:ss", where:
- hh represents the hour
- mm represents the minute
- ss represents the second
Note: All components are required!
Below is an example of a time declaration in a schema:
The element in the document should look like this:
Or like this:
Time Zone
If you need to specify a time zone, you can also input a time using Coordinated Universal Time (UTC) by appending a "Z" to the time, like this:
Or you can specify an offset from Coordinated Universal Time by appending a positive or negative time to the time, like this:
DateTime Data Type
The dateTime data type is used to define a date and time.
A dateTime is defined using the following format: "YYYY-MM-DDThh:mm:ss", where:
- YYYY represents the year
- MM represents the month
- DD represents the day
- T indicates the start of the time component, which is required
- hh represents the hour
- mm represents the minute
- ss represents the second
Note: All components are required!
Below is an example of a dateTime declaration in a schema:
The element in the document should look like this:
Or like this:
Time Zone
If you need to specify a time zone, you can also input a dateTime using Coordinated Universal Time (UTC) by appending a "Z" to the dateTime, like this:
Or you can specify an offset from Coordinated Universal Time by appending a positive or negative time to the time, like this:
The duration data type is used to specify a time interval.
A time interval is specified using the following format: "PnYnMnDTnHnMnS", where:
- P indicates the period (required)
- nY represents the number of years
- nM represents the number of months
- nD represents the number of days
- T indicates the start of the time component (required if you are specifying hours, minutes, and seconds)
- nH represents the number of hours
- nM represents the number of minutes
- nS represents the number of seconds
Below is an example of a duration declaration in a schema:
The element in the document should look like this:
The above example represents a period of 5 years.
Or like this:
The above example represents a period of 5 years, 2 months, and 10 days.
Or like this:
The above example represents a period of 5 years, 2 months, 10 days, and 15 hours.
Or like this:
The above example represents a period of 15 hours.
Negative Duration
To specify a negative duration, enter a minus sign before P:
The above example 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 the date - day (DD) |
gMonth | Defines a part of the date - month (MM) |
gMonthDay | Defines a part of the date - month and day (MM-DD) |
gYear | Defines a part of the date - year (YYYY) |
gYearMonth | Defines a part of the date - year and month (YYYY-MM) |
time | Defines a time value |
Restrictions on Date Data Types
Restrictions that can be used with date data types:
- enumeration
- maxExclusive
- maxInclusive
- minExclusive
- minInclusive
- pattern
- whiteSpace