Search code examples
xpathaemjcr

Date range comparison in CQ using XPATH


I'm using the following query to get nodes based on last modified date in CQ.

/jcr:root/content/scaffoldes/properties//*[@jcr:primaryType = 'nt:unstructured' and (@sling:resourceType = 'acme/components/content/scaffoldItem' or @sling:resourceType = 'acme-core/components/data/property') and @jcr:content/cq:lastModified >= xs:dateTime('2000-01-01T00:00:00.000-08:00') and @jcr:content/cq:lastModified < xs:dateTime('2014-12-31T00:00:00.000-08:00') and not(@isHidden)] order by @jcr:score

we have used

  http://localhost:4502/crx/explorer/ui/search.jsp

To test this query. But, even after giving a huge date range (2000 - 2016) this query is returning nothing.

But If we remove the date range part, this query returns nodes.

Any pointer to correct this would be helpful.

Thanks and Regards, San

Notes

The date string is create with the following code:

Calendar cal = Calendar.getInstance();
cal.setTime(start);
String startDate = ValueFactoryImpl.getInstance().createValue(cal).getString();

Solution

  • Sorry for any confusion caused. I found that the node which I'm trying to query doesn't have a cq:lastModified property. So modified the query to include the cq:lastReplicated in the condition.

     ... and ((@jcr:content/cq:lastModified >= xs:dateTime('2000-01-01T00:00:00.000-08:00') and @jcr:content/cq:lastModified < xs:dateTime('2016-02-11T15:52:57.090-08:00')) or (@jcr:content/cq:lastReplicated >= xs:dateTime('2000-01-01T00:00:00.000-08:00') and @jcr:content/cq:lastReplicated < xs:dateTime('2016-02-11T15:52:57.090-08:00'))) and ...