AnsweredAssumed Answered

Querying Alfresco on Month of a Date field

Question asked by smsoumitra on Jan 19, 2015
Latest reply on Jan 19, 2015 by mlagneaux
Is there any way to query on the basis of month and year of any date field in Alfresco. I'm using aspect where in one of the custom properties is of date type. But I need to query on files based on the month and year of the field.

This is what I'm doing.
 
 String Query = "select d.*,o.* from cmis:document as d join sc:mine as o on d.cmis:objectid = o.cmis:objectid";
   //"where MONTH(o.sc.createdDateTime) = JAN"

And then something like:

ItemIterable<QueryResult> results = session.query(Query, false);
for(QueryRsult qr : results){
   Calendar cal = (Calendar) qr.getPropertyValueByQueryName("o.sc:createdDateTime");
   Integer month = cal.get(Clendar.MONTH);
   Integer year = cal.get(Clendar.YEAR);
//Select the required month/year and then proceed
}

But in this approach every time we have to loop through all the results. It will really helpful if I can query on the month of sc:createdDateTime

Outcomes