# Fix an invalid xs:date value in XML

Source: https://xsdhub.com/learn/xsd-invalid-date

Replace ambiguous date formats with valid xs:date values. Test a complete XML/XSD example and check calendar dates, time zones and empty values.

## Use year-month-day for ordinary modern dates

For 26 October 2026, use 2026-10-26 rather than 26/10/2026. In this example the element is typed as xs:date. The slash-separated value is well-formed XML but fails schema validation. A dateTime field is a different type and can require a time component.

## Check the calendar, not only the format

2026-02-30 has the expected visual shape but is not a valid date. Leap years matter too. Validate generated values rather than merely checking them with a format-only regular expression.

## Do not guess an ambiguous date

03/04/2026 may mean March 4 or April 3. Confirm the source locale or data contract before converting it. Reordering digits without that context can produce schema-valid but factually wrong data.

## Time zones and missing values

xs:date permits an optional timezone such as Z or +02:00; the receiving contract may impose narrower rules. An empty element is not automatically a valid date. Omitting an optional element and using xsi:nil on a nillable element are distinct choices that depend on the schema.

## Validate after export

Keep the intended calendar date intact when your source uses timestamps and timezone conversion. Test the exported XML against the receiver’s XSD. Passing xs:date validation confirms its datatype, not a business rule such as delivery occurring after order placement.

## Primary references

- [W3C XML Schema datatypes: date](https://www.w3.org/TR/xmlschema-2/#date)
