[xquery-talk] XQuery functions for date calculation/manipulation

David Sewell dsewell at virginia.edu
Thu Aug 26 12:53:23 PDT 2004

We're going to need to make some decisions about date representations
that will be partly constrained by the ability of XQuery to do various
manipulations and arithmetic with calendar dates, and I could use
guidance on what is and isn't possible with the current specs.

The basic situation is a large collection of historical documents stored
in XML that bear dates, where in many cases the exact date is uncertain.
For example, a letter known to be from 1832 may have a dateline reading
merely "Sunday". If we want to enable searches on these documents with
granularity down to the day, we must generate a sequence of all possible
dates for the document. It could of course be done by hand:

<date value="1832-01-07|1832-01-14 ... 1832-12-29">Sunday [1832]</date>

but needless to say that's a lot of work. It's not hard to write a
function that takes an xs:date and adds xdt:dayTimeDuration("P7DT0M")
times (1 to 51) to generate the same list. You still need to look up the
start date manually, however. Is there any way to get XQuery to generate
"every Sunday in 1832" or "every 2nd Thursday of the month in 1832" in a
higher-level way? Can it do Gregorian calendar lookups? (I can't see
that it has a concept of "day of the week" anywhere.)

David S.

David Sewell, Editorial and Technical Manager
Electronic Imprint, The University of Virginia Press
PO Box 400318, Charlottesville, VA 22904-4318 USA
Courier: 310 Old Ivy Way, Suite 302, Charlottesville VA 22903
Email: dsewell at virginia.edu   Tel: +1 434 924 9973
Web: http://www.ei.virginia.edu/

More information about the talk mailing list