« Return to Thread: Is there a better way? Getting earliest date

Re: Is there a better way? Getting earliest date

by Adam Retter-3 :: Rate this Message:

Reply to Author | View in Thread

I would probably change how you obtain the year to use year-from-date
function - e.g. -

year-from-date($min_date/@ms:value)




2009/6/25 PencilEd <gstewart@...>:

>
> I was able to get this to work with the code below -
>
> Basically, I'm given a date that looks like this:
>        <ms:Dates>
>                <ms:Date ms:type="posted" ms:value="2008-07-23"/>
>        </ms:Dates>
>
> I've a bunch in my collection, but need to get the year (for starters) of
> the earliest one... so, while I'm almost certain there's a better way (and
> hoping someone can teach me), I'm doing this:
>
> ---Code---
> declare function analysis:earliest() as xs:integer {
>  let $ordered_dates := for $the_dates in collection($collection_all
> )/ms:Resource/ms:Dates/ms:Date
>                                order by $the_dates/@ms:value
>                                return $the_dates
>  let $min_date := $ordered_dates[1]
>  let $year_string := substring($min_date/@ms:value, 1, 4)
>  return xs:integer($year_string)
> };
> ---End Code---
> --
> View this message in context: http://www.nabble.com/Is-there-a-better-way---Getting-earliest-date-tp24205954p24205954.html
> Sent from the exist-open mailing list archive at Nabble.com.
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Exist-open mailing list
> Exist-open@...
> https://lists.sourceforge.net/lists/listinfo/exist-open
>



--
Adam Retter

eXist Developer
{ United Kingdom }
adam@...
irc://irc.freenode.net/existdb

------------------------------------------------------------------------------
_______________________________________________
Exist-open mailing list
Exist-open@...
https://lists.sourceforge.net/lists/listinfo/exist-open

 « Return to Thread: Is there a better way? Getting earliest date