Discussion:
Datediff in XPath
(too old to reply)
nick
2009-02-12 21:52:00 UTC
Permalink
Is there a way to get the difference between 2 dates in XPath? Eg. how
do I calculate age from date of birth? Thanks!
Martin Honnen
2009-02-13 13:05:54 UTC
Permalink
Post by nick
Is there a way to get the difference between 2 dates in XPath? Eg. how
do I calculate age from date of birth? Thanks!
XPath 2.0 has support for the xs:date and the xs:dateTime data types and
operators on them.
So in XPath 2.0 you can do e.g.
current-date() - xs:date('1956-12-07')
to get a xs:dayTimeDuration. You could then extract the days and divide
by 365 to find the years e.g.
days-from-duration(current-date() - xs:date('1956-12-07')) idiv 365
should give 52.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
nick
2009-02-16 03:37:38 UTC
Permalink
Post by Martin Honnen
Post by nick
Is there a way to get the difference between 2 dates in XPath? Eg. how
do I calculate age from date of birth? Thanks!
XPath 2.0 has support for the xs:date and the xs:dateTime data types and
operators on them.
So in XPath 2.0 you can do e.g.
   current-date() - xs:date('1956-12-07')
to get a xs:dayTimeDuration. You could then extract the days and divide
by 365 to find the years e.g.
   days-from-duration(current-date() - xs:date('1956-12-07')) idiv 365
should give 52.
Thanks Martin I'll try that out.

Loading...