Formatting valid xs:dateTime fields with PHP
Recently I had to compose some XML documents that needed to be validated with XSDs. All fine of course, but I had some problem with two date/time fields that according to the XSD were supposed to be xs:dateTime fields. Googling around I found a lot of references to the ISO8601 format, so I decided to format my date using the DATE_ISO8601 constant. That did not work though.
After quite some time puzzling on the issue I decided to just fire off my problem to Twitter.
Awesome as Twitter is for these kinds of things, I had my answer very soon:
Apparently the DATE_ISO8601 is missing the ":" in the timezone offset, and the solution is very simple:
date('c' );
According to the PHP manual, the 'c' string also gives the ISO 8601 formatted string. However, this one is correct and working. Thanks to David Zuelke for giving me this answer, as it ensured my progress in this specific task
September 8, 2009 - tags: php, xsd, validation, xml, datetime
David Zülke: A whole article to praise my little help, that really wasn't necessary, Stefan
With hindsight, my recommendation should actually have been "use RELAX NG", although they use the same data types, so you'd still have had that problem
Paul M. Jones: David, it might not have been "necessary", but I think it shows good form on skoop's part. Nicely done, Stefan, nicely done.
left: David: I like to share such solutions with the community, since it is the community as a whole that also shares their solutions with me
Also, Relax NG would not have been an option, since we also depend on an external web service here that also validates using XSD.
Paul: Just my point. Small solutions like these can make the difference between hours of puzzling and remembering that someone solved the problem before you