Discussion:
[xquery-talk] create a sequence of dates
Jakob Fix
2014-04-12 20:58:01 UTC
Permalink
Hi,

I have a "sparse sequence" of dates that I'd like to pad with the missing
ones.

So I thought I'd find the min and the max dates, create a sequence from min
to max and then create a union with the existing sequence and get the
distinct values.

unfortunately, creating a sequence of dates doesn't seem that simple. This:

let $d1 := xs:date("2014-03-01")
let $d2 := xs:date("2014-03-31")
return ($d1 to $d2)

doesn't work. There is probably a way to create a recursive function using
durations, but maybe it's just me not seeing the forest because of all the
tress...

cheers,
Jakob.
Andy Bunce
2014-04-12 21:59:42 UTC
Permalink
How about:

let $d1 := xs:date("2014-03-02")
let $d2 := xs:date("2014-04-21")
let $days:=0 to days-from-duration($d2 - $d1)
return $days!($d1+ . *xs:dayTimeDuration('P1D'))

Cheers
/Andy
Post by Jakob Fix
Hi,
I have a "sparse sequence" of dates that I'd like to pad with the missing
ones.
So I thought I'd find the min and the max dates, create a sequence from
min to max and then create a union with the existing sequence and get the
distinct values.
let $d1 := xs:date("2014-03-01")
let $d2 := xs:date("2014-03-31")
return ($d1 to $d2)
doesn't work. There is probably a way to create a recursive function using
durations, but maybe it's just me not seeing the forest because of all the
tress...
cheers,
Jakob.
_______________________________________________
http://x-query.com/mailman/listinfo/talk
Jakob Fix
2014-04-13 09:10:39 UTC
Permalink
Hi Andy, exactly what I needed, thanks a lot!

cheers,
Jakob.
Post by Andy Bunce
let $d1 := xs:date("2014-03-02")
let $d2 := xs:date("2014-04-21")
let $days:=0 to days-from-duration($d2 - $d1)
return $days!($d1+ . *xs:dayTimeDuration('P1D'))
Cheers
/Andy
Post by Jakob Fix
Hi,
I have a "sparse sequence" of dates that I'd like to pad with the missing
ones.
So I thought I'd find the min and the max dates, create a sequence from
min to max and then create a union with the existing sequence and get the
distinct values.
let $d1 := xs:date("2014-03-01")
let $d2 := xs:date("2014-03-31")
return ($d1 to $d2)
doesn't work. There is probably a way to create a recursive function
using durations, but maybe it's just me not seeing the forest because of
all the tress...
cheers,
Jakob.
_______________________________________________
http://x-query.com/mailman/listinfo/talk
Loading...