Schema Dtypes Date
# XML Schema Date/Time Data Types
## XSD Date and Time Data Types
Date and time data types are used for values that contain dates and times.
## Date Data Type
The date data type is used to define dates.
Dates are defined using the format: "YYYY-MM-DD", where:
* YYYY represents the year
* MM represents the month
* DD represents the day
**Note:** All components are required.
Here is an example of a date declaration in a schema:
An element in a document should look like this:
2002-09-24
### Time Zone
To specify a time zone, you can also input a date using Coordinated Universal Time (UTC) by adding a "Z" after the date - like this:
2002-09-24Z
Or you can specify an offset from UTC by adding a positive or negative time after the date - like this:
2002-09-24-06:00
Or
2002-09-24+06:00
## Time Data Type
The time data type is used to define times.
Times are defined using the format: "hh:mm:ss", where:
* hh represents the hour
* mm represents the minute
* ss represents the second
**Note:** All components are required!
Here is an example of a time declaration in a schema:
An element in a document should look like this:
09:00:00
Or like this:
09:30:10.5
### Time Zone
To specify a time zone, you can also input a time using Coordinated Universal Time (UTC) by adding a "Z" after the time - like this:
09:30:10Z
Or you can specify an offset from UTC by adding a positive or negative time after the time - like this:
09:30:10-06:00
Or
09:30:10+06:00
## DateTime Data Type
The dateTime data type is used to define dates and times.
DateTimes are defined using the format: "YYYY-MM-DDThh:mm:ss", where:
* YYYY represents the year
* MM represents the month
* DD represents the day
* T is the required separator for the time part
* hh represents the hour
* mm represents the minute
* ss represents the second
**Note:** All components are required!
Here is an example of a dateTime declaration in a schema:
An element in a document should look like this:
2002-05-30T09:00:00
Or like this:
2002-05-30T09:30:10.5
### Time Zone
To specify a time zone, you can also input a dateTime using Coordinated Universal Time (UTC) by adding a "Z" after the dateTime - like this:
2002-05-30T09:30:10Z
Or you can specify an offset from UTC by adding a positive or negative time after the time - like this:
2002-05-30T09:30:10-06:00
Or
2002-05-30T09:30:10+06:00
## Duration Data Type
The duration data type is used to specify time intervals.
Time intervals are specified using the format: "PnYnMnDTnHnMnS", where:
* P is the period designator (required)
* nY specifies the number of years
* nM specifies the number of months
* nD specifies the number of days
* T is the time designator (required if you intend to specify hours, minutes, and seconds)
* nH specifies the number of hours
* nM specifies the number of minutes
* nS specifies the number of seconds
Here is an example of a duration declaration in a schema:
An element in a document should look like this:
P5Y
The example above specifies a period of 5 years.
Or like this:
P5Y2M10D
The example above specifies a period of 5 years, 2 months, and 10 days.
Or like this:
P5Y2M10DT15H
The example above specifies a period of 5 years, 2 months, 10 days, and 15 hours.
Or like this:
PT15H
The example above specifies a period of 15 hours.
### Negative Duration
To specify a negative duration, enter a minus sign before the P:
-P10D
The example above specifies a negative period of 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 date data types:
* enumeration
* maxExclusive
* maxInclusive
* minExclusive
* minInclusive
* pattern
* whiteSpace
YouTip