0

I don't understand why the xsd rule I have created for a date is not working. The rule is: <xs:element name="scan_date" type="xs:date" /> which, accoring to XML Schema Date on W3Schools is specified in the following form "YYYY-MM-DD", yet when the XML Parser in SQL encounters <scan_date>2006-12-15</scan_date> it fails because it doesn't accept the date as valid, yet if I swap the 12 and 15 round it does.

Simon Martin
  • 4,203
  • 7
  • 56
  • 93
  • Could you construct and post a short but complete script that demonstrates the problem? – Damien_The_Unbeliever Sep 05 '11 at 14:42
  • Sounds to me like your problem is rather SQL server locale setting expecting a `YYYY-DD-MM` date format. – Filburt Sep 11 '11 at 19:41
  • @Filburt - I _think_ you're probably right. The user account for SQL is using English rather than British English for it's default language. Unfortunately I can't change the locale (changing it would break existing functionality) and I can't change the data (that's provided from a 3rd party). All I can do is work with the xsd, do you know if there's a way to supply date format information? – Simon Martin Sep 12 '11 at 09:33
  • @Simon The only way I can think of is changing the data type from `xs:date` to a regex equivalent. – Filburt Sep 13 '11 at 19:38
  • @Filburt - the alternative is xs:string I guess? – Simon Martin Sep 14 '11 at 14:22

1 Answers1

0

A possible solution using xs:string and a regex restriction:

<xs:element name="scan_date" type="dateType"/>

<xs:simpleType name="dateType">
    <xs:restriction base="xs:string">
        <xs:pattern value="\d{4}(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])"/>
    </xs:restriction>
</xs:simpleType>

... adopted from XSD date format overriding

Community
  • 1
  • 1
Filburt
  • 17,626
  • 12
  • 64
  • 115