[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.net
Fri Jul 9 15:35:14 PDT 2010

  Grouping By Time / Round xs:time to just the hour?
Awesome.  Thanks everyone!  Michael, I also really like the shorthand
example.  Very cool stuff.  Here is what I ended up with.

 let $m :=
= 'QUERY']
 for $date in distinct-values(for $dt in (for $ts in $m/timestamp return
 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>

Thanks again!

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


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.
First Name
Last Name
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-2013 All Rights Reserved.