Hi Ryan,

Fun question! Hadn't done it yet, but that doesn't matter. How about this? It 
returns a list of all workable days. Wrap in a count to get a number. Perhaps 
not the fastest/smartest solution, but it should get you going..

import module namespace functx = "http://www.functx.com"; at 
"/MarkLogic/functx/functx-1.0-nodoc-2007-01.xqy";

let $holidays := (xs:date("2011-06-13")) (: second easter day:)

let $start := xs:date("2011-06-09")
let $end := xs:date("2011-06-16")

return
    for $day in (0 to days-from-duration($end - $start))
    let $date := $start + xs:dayTimeDuration(concat("P",$day,"D"))
    let $weekday := functx:day-of-week($date)
    let $is-weekend := ($weekday = (0, 6))
    let $is-holiday := exists(index-of($date, $holidays))
    where not($is-weekend) and not($is-holiday)
    return
        $date

Kind regards,
Geert

Van: [email protected] 
[mailto:[email protected]] Namens [email protected]
Verzonden: donderdag 16 juni 2011 0:32
Aan: [email protected]
Onderwerp: [MarkLogic Dev General] Net Working Days calculation?

Has anyone done a Net Working Days calculation in XQuery? This would be the 
number of business days between a start and end date. Holiday inclusion would 
be awesome.

-Ryan
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to