[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

parsing dates

James Cummings james+xquery at blushingbunny.net
Tue Oct 6 01:05:27 PDT 2009


  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


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.