const person = { dob: xs.date("1979-02-03") };
const thrirtyYearsAgo = fn.currentDate().subtract(xs.yearMonthDuration("P30Y"));
person.dob < thrirtyYearsAgo; // true

You can do date math with xs.duration types. In the above case, I'm subtracting 
30 years from the current date. xs.date.prototype.subtract() returns an 
xs.date. You can compare that xs.date to any other xs.date. To do this 
comparison in MarkLogic's indexes you'll need to create a range index 
<https://docs.marklogic.com/guide/concepts/indexing#id_51573>. A range index, 
as its name implies, queries efficiently for ranges of typed values, for 
example, dates less than thirty ago from today.

cts.rangeQuery(cts.jsonPropertyReference('dob'), '<', thrirtyYearsAgo); // 
requires a range index of type xs:date on the dob JSON property


Justin


> On May 22, 2017, at 1:08 PM, Shiv Shankar <shiv.shivshan...@gmail.com> wrote:
> 
> Hi,
> There is a dob json property in the documents and I need to search on dob 
> based on age wise i.e age > 30, age >30 and age <50.  Any samples to 
> calculate age and compare in the search queries?
> 
> Thanks
> Shan.
> 
> 
> 
> _______________________________________________
> General mailing list
> General@developer.marklogic.com
> Manage your subscription at: 
> http://developer.marklogic.com/mailman/listinfo/general

_______________________________________________
General mailing list
General@developer.marklogic.com
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to