Discussion:
Need xquery function for "number of days between two dates"
sudheshna iyer
2013-04-12 17:04:11 UTC
Permalink
Hello Team,

I need a xquery function which takes two dates and return number of days that lapsed between these two dates. Input to this function can be a 2 strings of type "mm/dd/yyyy 00:00:00".

Can any of you have a function handy to do this?

Thank you very much in advance.
Martin Honnen
2013-04-12 17:25:01 UTC
Permalink
Post by sudheshna iyer
I need a xquery function which takes two dates and return number of days
that lapsed between these two dates. Input to this function can be a 2
strings of type "mm/dd/yyyy 00:00:00".
Can any of you have a function handy to do this?
Well there is an xs:dateTime data type supporting this:

days-from-duration(current-dateTime() - xs:dateTime('2013-01-01T00:00:00'))



You would first need to convert your date time format to the xs:dateTime
format of yyyy-mm-ddThh:mm:ss respectively construct xs:dateTime values
from your format.
Michael Kay
2013-04-12 17:30:11 UTC
Permalink
You just use the subtraction operator "-" with operands of type xs:date, this returns a dayTimeDuration, which you can turn into an integer number of days by dividing it by xs:dayTimeDuration('P1D').

Michael Kay
Saxonica
Post by sudheshna iyer
Hello Team,
I need a xquery function which takes two dates and return number of days that lapsed between these two dates. Input to this function can be a 2 strings of type "mm/dd/yyyy 00:00:00".
Can any of you have a function handy to do this?
Thank you very much in advance.
_______________________________________________
http://x-query.com/mailman/listinfo/talk
Loading...