Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

XML Schema Date/Time Data Types

XSD Date and Time Data Types


Date and time data types are used to contain values of dates and times.


Date Data Type

The date data type is used to define a date.

A date is defined with the format "YYYY-MM-DD", where:

**Note:** All components are required

The following is an example of a date declaration in a schema:

The element in the document should look like this:

2002-09-24

Timezone

To specify a time zone, you can also enter a date using Coordinated Universal Time (UTC time) 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


h2>Time Data Type

The time data type is used to define a time.

A time is defined with the following format: "hh:mm:ss", where

Note: All components are required!

The following is an example of a time declaration in a schema:

The element in the document should look like this:

09:00:00

or like this:

09:30:10.5

Timezone

To specify a time zone, you can also enter a time using Coordinated Universal Time (UTC time) 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 a date and a time.

A datetime is defined with the following format: "YYYY-MM-DDThh:mm:ss", where:

Note: All components are required!

The following is an example of a datetime declaration in a schema:

The element in the document should look like this:

2002-05-30T09:00:00

or like this:

2002-05-30T09:30:10.5

Timezone

To specify a time zone, you can also enter a datetime using Coordinated Universal Time (UTC time) 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 a time interval.

A time interval is specified with the format "PnYnMnDTnHnMnS", where:

The following is an example of a duration declaration in a schema:

The element in the document should look like this:

P5Y

The example above indicates a period of 5 years.

or like this:

P5Y2M10D

The example above indicates a period of 5 years, 2 months, and 10 days.

or like this:

P5Y2M10DT15H

The example above indicates a period of 5 years, 2 months, 10 days, and 15 hours.

or like this:

PT15H

The example above indicates a period of 15 hours.

Negative Duration

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

-P10D

The example above indicates a period of negative 10 days.


Date and Time Data Types

Name Description
date Define a date value
dateTime Define a date and time value
duration Define a time interval
gDay Define a part of a date - day (DD)
gMonth Define a part of a date - month (MM)
gMonthDay Define a part of a date - month and day (MM-DD)
gYear Define a part of a date - year (YYYY)
gYearMonth Define a part of a date - year and month (YYYY-MM)
time Define a time value

Restriction on Date Data Types

Restrictions that can be used with date data types: