Start a new topic

Query with "and" and "or"

 Hi guys,

My collection has for example 3 fields, companyid, date1 and date2.

I need to do a query where criteria is equal company id


date1 is less than a date and date1 is greater than a date


date2 is less than a date and date2 is greater than a date

it is like

if(id == "companyId") {

   if((date1 >= dateA && date1 <= dateB) or (date2 >= dateA && date2 <= dateB)) {

      // do sth



I tried the following but doesn't work:

        DateTime dtLess1Day = dtf.parseDateTime(sb1.toString() + "23:59:59.999Z");
        DateTime dtPlus1Day = dtf.parseDateTime(sb2.toString() + "00:00:00.000Z");

        Log.i(TAG, "dt1 = "+dtLess1Day);
        Log.i(TAG, "dt2 = "+dtPlus1Day);

        q.equals("companyid", AppController.getInstance().getUserData().getCompanyId());

        q.greaterThan("_kmd.ect", dtLess1Day.toString());

        q.lessThan("_kmd.ect", dtPlus1Day.toString());

        q.or(q.greaterThan("date_input", dtLess1Day.toString()).and(q.lessThan("date_input", dtPlus1Day.toString())));

        q.addSort("_kmd.ect", AbstractQuery.SortOrder.ASC);

        aggregate.get(q, new KinveyListCallback<ProdProcess>() {


Appreciate any assistance please. Thanks !


Mark Thien


1 person has this question




There was a recent update to the Android library which addressed a shortcoming in how queries were being handled.  Can you please try that update and see if it addresses your issues that you've outlined here?


Login or Signup to post a comment