Skip to main content
XMLDir

Search 261 pages — tools, formats, elements, namespaces, XPath, datatypes, glossary, parse errors, schema errors, use cases, blog and product.

XSD datatype

xs:gYear and friends

Gregorian fragments — a year, a month, a day, or a pair of them — for the dates that are genuinely partial.

The g-types cover recurring or partial dates: gYear (2026), gYearMonth (2026-08), gMonth (--08), gDay (---18) and gMonthDay (--08-18). The leading hyphens are part of the lexical form and are what people forget.

gMonth and gMonthDay are for recurring dates — a birthday, a fiscal month — where the year is deliberately absent rather than unknown.

Lexical space
YYYY for gYear; YYYY-MM for gYearMonth; --MM, ---DD, --MM-DD for the rest.
Derives from
Primitive type
Category
Date and time types
Facets
minInclusive, maxInclusive, minExclusive, maxExclusive, pattern, enumeration, whiteSpace

What validates

Every literal below is put through the schema validator on each test run, against the schema at the foot of this page.

  • 2026
  • -0044
  • 2026

What does not

  • 26

    The year is four digits minimum.

  • 2026-08

    That is a gYearMonth, not a gYear.

What catches people out

  • gMonth is '--08' with two leading hyphens, and gDay is '---18' with three. Omitting them is the usual failure.
  • Years before 1 CE are negative and there is no year zero: -0001 is 1 BCE.
  • All of them accept an optional timezone, same as xs:date.

The schema used

This is the exact schema the literals above are validated against. Paste it into the validator with one of them to see the result yourself.

schema.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="v" type="xs:gYear"/>
</xs:schema>

Open the XSD validator

Related

All 29 datatypes and facets

Get started

Bring order to the XML your team can't afford to ignore.

Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.