[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?

Oliver Hallam oliver at xqsharp.com
Thu Jul 8 20:51:14 PDT 2010


  Grouping By Time / Round xs:time to just the hour?
  On 08/07/2010 18:21, Andrew Serff wrote:
> So two questions:
> 1) How do I add the leading 0 to the output of hours-from-dateTime?
> 2) Is there an easier way of doing this?
>
> Thanks for the help!
> Andrew
>

1)  The only way i can think of is

if ($hour<  10) then concat('0', $hour) else $hour

2) You could just group your input by the result of hour-from-dateTime:

<metrics>
{
   let $m := collection('metricsCollection.xml')//metrics/metric[action = 'QUERY']
   let $timestamps := for $ts in $m/timestamp return xs:dateTime($ts)
   for $hour in distinct-values(for $timestamp in $today return hour-from-dateTime($timestamp))
   let $hours-timestamps := $timestamps[hour-from-dateTime($timestamp) = $hour]
   return
     <res><h>{$hour}</h><metrics>{count($hours-timestamps)}</metrics></res>
}
</metrics>

Of course if you actually want your date in the result then you are 
still stuck with converting your hour back to a time.

Oliver




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