Hi Lusha Originally, I was thinkig "do your homework" but when I tried it, I found I underestimated number of small details, hidden in this task... Here is my version of solution:
for $doc in //Document let $datestr := $doc/@time let $datearr := tokenize($datestr, '/') let $year := $datearr[3] let $month := format-number(xs:int($datearr[2]), '#00') let $day := format-number(xs:int($datearr[1]), '#00') let $dateisostr := concat($year, '-', $month, '-', $day) where $dateisostr > '2010-06-01' and $dateisostr < '2011-01-01' (: let $date := xs:date($dateisostr) where $date > xs:date('2010-06-01') and $date < xs:date('2011-01-01') :) return $doc
Concept:
1. one has to get some values, which are comparable to your criteria. There are more options like 'normalized' string, xs:date value and more could be found. 2. my solution is using string, which follows ISO format. 3. if you comment out the working "where" line and use the commented part, you will use values converted into xs:date
Make sure, your code follows your real order of month and day - from sample values I was unable to find, which is really used as all day and month values are smaller then 13
I had to do this task in past with dateTime and my recommendation for performance is:
- use only dateTime in Zulu timezone as they can be easily compared as strings. - try to prevent comparing xs:dateTime, as this is not indexed value and queries are slower. If you can use original strings, you will take advantage of existing indices and speed will be much better.
But it is much more important to get familiar with the concept and not to optimize sooner, then is really neede, so do not be sidetracked by my last hint before you get correct results.
With best regards
Jan
*Ing. Jan Vlčinský* CAD programy Slunečnicová 338/3, 734 01 Karviná Ráj, Czech Republic tel: +420-597 602 024; mob: +420-608 979 040 skype: janvlcinsky; GoogleTalk: jan.vlcinsky@gmail.com http://cz.linkedin.com/in/vlcinsky
On 18 July 2011 20:20, Lusha Wang lwang40@syr.edu wrote:
For example:
<Documents> <Document id="1" time="5/2/2010"> </Document> <Document id="2" time="4/8/2011"> </Document> <Document id="3" time="6/9/2010"> </Document> <Document id="4" time="8/10/2010"> </Document> </Documents>
How to query the documents that are within May 2010 to April 2011? Thanks ________________________________________ From: Dimitar Popov [Dimitar.Popov@uni-konstanz.de] Sent: Monday, July 18, 2011 1:11 PM To: basex-talk@mailman.uni-konstanz.de Cc: Lusha Wang Subject: Re: [basex-talk] help! database query for specific time period
Hi Serena,
Could you give more information about your case - I can't undestand what exactly do you want to do. Otherwise, here is a short example of using the xs:time type:
<Documents> <Document id="1" time="01:00:00"> </Document> <Document id="2" time="02:00:00"> </Document> <Document id="3" time="15:00:00"> </Document> <Document id="4" time="16:00:00"> </Document> </Documents> //Document[@time cast as xs:time > "13:00:00" cast as xs:time]
Greetings, Dimitar
Am Montag, 18. Juli 2011, 16:24:22 schrieb Lusha Wang:
Hi Guys Is it possible to query for specific time period of data? I
really
appreciate any help. <Documents> <Document id=" " time=" "> .............. </Document> <Document id=" " time=" "> .............. </Document>
</Documents>
Sincerely Serena
BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk