|
[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.comThu Jul 8 20:51:14 PDT 2010
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! 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








