XSD Date Time - XSD

What is the use of date and time data types in XSD?

Date and Time data types in XSD are used for representing date and time in XML documents.

<xs:date> data type

<xs:date> data type is used for representing date in YYYY-MM-DD format.

  • YYYY − represents year
  • MM − represents month
  • DD − represents day

<xs:date> Example

Element declaration in XSD

Element usage in XML

<xs:time> data type

<xs:time> data type is used for representing time in hh:mm:ss format.

  • hh − represents hours
  • mm − represents minutes
  • ss − represents seconds

<xs:time> Example

Element declaration in XSD

Element usage in XML

<xs:datetime> data type

<xs:datetime> data type is used for representing date and time in YYYY-MM-DDThh:mm:ss format.

  • YYYY − represents year
  • MM − represents month
  • DD − represents day
  • T − represents start of time section
  • hh − represents hours
  • mm − represents minutes
  • ss − represents seconds

<xs:datetime> Example

Element declaration in XSD

Element usage in XML

<xs:duration> data type

<xs:duration> data type is used for representing time interval in PnYnMnDTnHnMnS format. Each component is optional except P.

  • P − represents start of date section
  • nY − represents year
  • nM − represents month
  • nD − represents day
  • T − represents start of time section
  • nH − represents hours
  • nM − represents minutes
  • nS − represents seconds

<xs:duration> Example

Element declaration in XSD

Element in xml are used for representing period of 6 years, 3 months, 10 days and 15 hours.

Date Data Types

Below is the list of frequently used date data types.

S.No.

Name & Description

1.

Date

This is used for representing a date value

2.

dateTime

This is used for representing a date and time value

3.

Duration

This is used for representing a time interval

4.

gDay

This is used for representing a part of a date as the day (DD)

5.

gMonth

This is used for representing a part of a date as the month (MM)

6.

gMonthDay

This is used for representing a part of a date as the month and day (MM-DD)

7.

gYear

This is used for representing a part of a date as the year (YYYY)

8.

gYearMonth

This is used for representing a part of a date as the year and month (YYYY-MM)

9.

Time

This is used for representing a time value

Restrictions

Below are the types of restrictions that can be used with Date data types

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

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

XSD Topics