Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

XML Schema Date/Time data type


May 28, 2021 XML Schema


Table of contents


XSD Date and Time data type

The XSD date and time data type defines the date and time in the document.


The date and time data type is used to contain the value of the date and time.


Date Data Type

The date data type is used to define the date.

Dates are defined in this format: "YYYY-MM-DD", where:

  • YYYY represents the year
  • MM represents the month
  • DD represents the number of days

Note: All ingredients are required

Here's an example of a date declaration in schema:

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

The elements in the document should look something like this:

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

Time

To specify a time zone, you can also enter a date using UTC time by adding a "Z" after the date - for example:

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

Alternatively, you can specify an offset based on the world adjustment time by adding a positive or negative time after the date - for example:

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

or

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

Tip: When using xs:date() to cast a string as a date type, the format of string parameters needs to be strictly followed: yyyy-mm-dd.



h2; Time Data Type

The time data type is used to define the time.

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

  • hh indicates the hour
  • mm indicates minutes
  • ss represents seconds

Note: All ingredients are required!

Here's an example of a time statement in schema:

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

The elements in the document should look something like this:

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

Or something like this:

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

Time

To specify a time zone, you can also enter a time using UTC time by adding a "Z" after the time - for example:

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

Alternatively, you can specify an offset based on the world adjustment time by adding a positive or negative time after time - for example:

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

or

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


DateTime Data Type

The date-time data type is used to define the date and time.

Date time is defined in the following format: "YYYY-MM-DDThh:mm:ss", where:

  • YYYY represents the year
  • MM represents the month
  • DD represents the day
  • T represents the start of the required time section
  • hh indicates the hour
  • mm indicates minutes
  • ss represents seconds

Note: All ingredients are required!

Here's an example of a date-time declaration in schema:

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

The elements in the document should look something like this:

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

Or something like this:

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

Time

To specify a time zone, you can also enter a date time using UTC time by adding a "Z" after the date time - for example:

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

Alternatively, you can specify an offset based on the world adjustment time by adding a positive or negative time after time - for example:

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

or

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


h2; Duration Data Type

The duration data type is used to specify the interval.

The interval is specified in the following format: "PnYnMnDTnHnMnS", where:

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

Here's an example of a duration declaration in schema:

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

The elements in the document should look something like this:

<period>P5Y</period>

The example above represents a 5-year cycle.

Or something like this:

<period>P5Y2M10D</period>

The example above represents a 5-year, 2-month, and 10-day cycle.

Or something like this:

<period>P5Y2M10DT15H</period>

The example above represents a 5-year, 2-month, 10-day, and 15-hour cycle.

Or something like this:

<period>PT15H</period>

The example above represents a 15-hour cycle.

Negative duration

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

<period>-P10D</period>

The example above represents a period of minus 10 days.


The date and time data type

Name Describe
date Define a date value
Datetime Define a date and time value
duration Define an interval
gDay Define a part of the date - days (DD)
gMonth Define a part of the date - month (MM)
gMonthDay Define a part of the date - month and day (MM-DD)
gYear Define a part of the date - Year (YYYY)
gYearMonth Define a part of the date - year and month (YYYY-MM)
time Define a time value


Limiting date data types

Qualifications that can be used with date data types:

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

The above is about the XML Schema Date/Time data type.