How to compare dates in xpath to select nodes

I want to get nodes based on the condition specified in xpath to compare the date. How can I do this using xpath?

Do I need to use adjust-dateTime-to-timezone ?

+6
source share
1 answer

XPath 2.0 has a number of date and time functions and operators to help process dates.

Suppose you had an XML document:

 <doc> <event date="2011-02-05">foo</event> <event date="2011-08-01">bar</event> <event date="2011-08-20">baz</event> <event date="2011-11-07">qux</event> </doc> 

and you want to filter out @date events for those in August 2011.

You can use this XPath:

 /doc/event[xs:date(@date) le xs:date('2011-08-31') and xs:date(@date) ge xs:date('2011-08-01')] 

and he will select event elements for bar and baz .

+3
source

Source: https://habr.com/ru/post/895327/


All Articles