|
[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message] parsing datesJames Cummings james+xquery at blushingbunny.netTue Oct 6 01:05:27 PDT 2009
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
|
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
|






