|
[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message] Grouping By Time / Round xs:time to just the hour?Andrew Serff lists at serff.netFri Jul 9 15:35:14 PDT 2010
Awesome. Thanks everyone! Michael, I also really like the shorthand
example. Very cool stuff. Here is what I ended up with.
<metrics>
{
let $m :=
collection('c:/dev/andrew.serff/Libraries/saxon/metricsCollection.xml')//metrics/metric[action
= 'QUERY']
for $date in distinct-values(for $dt in (for $ts in $m/timestamp return
xs:dateTime($ts))
let $hour := hours-from-dateTime($dt)
return xs:time(concat(concat('0'[$hour<10], $hour), ":00:00")))
let $hour := hours-from-time($date)
let $metrics_today := $m[xs:time(xs:dateTime(timestamp)) > $date and
xs:time(xs:dateTime(timestamp)) < xs:time(concat(concat('0'[$hour<10],
$hour), ":59:59"))]
return <res><d>{$date}</d><metrics>{count($metrics_today)}</metrics></res>
}
</metrics>
Thanks again!
Andrew
On Thu, Jul 8, 2010 at 1:23 PM, Michael Kay <http://x-query.com/mailman/listinfo/talk> wrote:
>
> 1) The only way i can think of is
>>
>> if ($hour< 10) then concat('0', $hour) else $hour
>>
>>
> In XQuery 1.1 there's format-number($hour, '00'), but in the meantime
> there's
>
> substring(string(hour + 100), 2)
>
> or
>
> concat('0'[$hour<10], $hour)
>
> which have the advantage over the above of always producing a string, as
> well as being shorter.
>
> Michael Kay
> Saxonica
>
> _______________________________________________
> http://x-query.com/mailman/listinfo/talk
> http://x-query.com/mailman/listinfo/talk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://x-query.com/pipermail/talk/attachments/20100709/b050d56e/attachment.htm
|
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
|

Cart








