XSD Date and Time Data Types

For values containing date and time, the date and time data types are used.

Date Data Type:

To specify a date, the date data type is used. It is specified in the “YYYY-MM-DD” format and where all components are required. Here,

  • YYYY: Used to indicate the year.
  • MM: Used to indicate the month.
  • DD: Used to indicate the day.

Example: Date declaration in a schema:


An element in a document:

1995-11-16

Time Zones:

To specify a time zone:

Enter a date in UTC time by adding a “Z” behind the date:

Example:

1995-11-16Z

OR

Specify an offset from the UTC time by adding a positive or negative time behind the date:

Example 1:

1995-11-16-09:00

Example 2:

1995-11-16+09:00

Time Data Type:

To specify a time, the time data type is used. It is specified in the “hh:mm:ss” format and where all the components are required. Here,

  • hh: Used to indicate the hour.
  • mm: Used to indicate the minute.
  • ss: Used to indicate the second.

Example: Time declaration in a schema:


An element in a document:

21:00:00

Or:

21:30:01.7

Time Zones:

To specify a time zone:

Enter a time in UTC time by adding a “Z” behind the time:

Example:

21:30:10Z

OR

Specify an offset from the UTC time by adding a positive or negative time behind the time:

Example 1:

21:30:10-03:00

Example 2:

21:30:10+03:00

DateTime Data Type:

To specify a date and a time, the dateTime data type is used. It is specified in the “YYYY-MM-DDThh:mm:ss” format and where all the components are required. Here,

  • YYYY: Used to indicate the year.
  • MM: Used to indicate the month.
  • DD: Used to indicate the day.
  • T: Used to indicate the start of the required time section.
  • hh: Used to indicate the hour.
  • mm: Used to indicate the minute.
  • ss: Used to indicate the second.

Example: DateTime declaration in a schema:


An element in a document:

2020-08-08T08:00:00

Or:

2020-08-08T08:30:11.5

Time Zones:

To specify a time zone:

Enter a dateTime in UTC time by adding a “Z” behind the time:

Example:

2020-08-08T08:30:11Z

OR

Specify an offset from the UTC time by adding a positive or negative time behind the time:

Example 1:

2020-08-08T08:30:11-03:00

Example 2:

2020-08-08T08:30:11+03:00

Duration Data Type:

To specify a time interval, the duration data type is used. It is specified in the “PnYnMnDTnHnMnS” format. Here,

  • P: Used to indicate the period. It is a required component.
  • nY: Used to indicate the number of years.
  • nM: Used to indicate the number of months.
  • nD: Used to indicate the number of days.
  • T: Used to indicate the start of a time section. It is a required component when we are specifying hours, minutes, or seconds.
  • nH: Used to indicate the number of hours.
  • nM: Used to indicate the number of minutes.
  • nS: Used to indicate the number of seconds.

Example: Duration declaration in a schema:


An element in a document:

P2Y

Explanation:

In the above example, we are indicating a period of two years.

Or:

P2Y3M4D

Explanation:

In the above example, we are indicating a period of two years, three months, and four days.

Or:

P2Y3M4DT5H

Explanation:

In the above example, we are indicating a period of two years, three months, four days and five hours.

Or:

PT5H

Explanation:

In the above example, we are indicating a period of five hours.

Negative Duration:

We can enter a minus sign before P to indicate a negative duration.

Example:

-P4D

Explanation:

In the above example, we are indicating a period of minus four days.

Date and Time Data Types:

Name Uses
date Used to define a date value.
dateTime Used to define a date and time value.
duration Used to define a time interval.
gDay Used to define a part of a date – the day (DD).
gMonth Used to define a part of a date – the month (MM).
gMonthDay Used to define a part of a date – the month and day (MM-DD).
gYear Used to define a part of a date – the year (YYYY).
gYearMonth Used to define a part of a date – the year and month (YYYY-MM).
time Used to define a time value.

Restrictions on Date Data Types:

Restrictions used with Date data types:

  • enumeration
  • maxExclusive
  • maxInclusive
  • minExclusive
  • minInclusive
  • pattern
  • whiteSpace
Please follow and like us:
Content Protection by DMCA.com