|
[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message] parsing datesMichael Kay mike at saxonica.comTue Oct 6 08:09:56 PDT 2009
I don't know if eXist has any schema support. If it does, you can define a type genericDate that is a union of xs:date, xs:gYearMonth, and xs:gYear. You can't cast to the union type (sadly) but you can construct an element and validate against a schema that defines the element as a union type, and then atomize. OK, that's a bit longwinded. Sorry! Regards, Michael Kay http://www.saxonica.com/ http://twitter.com/michaelhkay > -----Original Message----- > From: http://x-query.com/mailman/listinfo/talk > [mailto:http://x-query.com/mailman/listinfo/talk] On Behalf Of James Cummings > Sent: 06 October 2009 00:05 > To: http://x-query.com/mailman/listinfo/talk > Subject: parsing dates > > Hi there, > > I've a silly question about the best way to parse dates. I'm > passing a parameter (in eXist) that is part of the URL for an > xquery and I want to separate it into its individual parts of > year month and day. I could test the string and do > substring-before and after and such, or create my own > function, but it seemed better practice to use the functions > like year-from-date and month-from-date. So I tried: > > let $date := request:get-parameter("date", ("1789-01-01")) > cast as xs:date let $year := fn:year-from-date($date) let > $month := fn:month-from-date($date) let $day := > fn:day-from-date($date) > > which works fine when the date is YYYY-MM-DD. But what I > want to achieve is being able to handle YYYY-MM-DD, YYYY-MM > or just YYYY. The last two give me an error of "xs:date must > not have hour, minute or second fields set" (erm... which it > doesn't, which is why I'm confused). I'm happy for $month and > $day to be empty if they don't exist. > > I'm sure it is something terribly obvious with the datatype. > Should I just be breaking it down to its component parts > myself? It just seemed like I was reinventing the wheel. > > Thanks for any suggestions. > > -James > _______________________________________________ > http://x-query.com/mailman/listinfo/talk > http://x-query.com/mailman/listinfo/talk
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|






