Search code examples
javaandroiddatetimeactiveandroid

Where clause with a DATE variable using ActiveAndroid


I'm new at Android dev, so I'm using ActiveAndroid to manage the DB and I'm having troubles using a query with a Date variable, I have this:

From fromQuery = new Select().from(Shift.class);

//It doesn't matter what currentShiftDates do.
CurrentShiftDates currentShiftDates = new CurrentShiftDates();

fromQuery = fromQuery.where("startDate > ? and startDate < ?",currentShiftDates.startDate,
                currentShiftDates.endDate);

return fromQuery.execute();

I had read that the query needs to pass the parameter as a long value, so I've tried with .getTime():

fromQuery = fromQuery.where("startDate > ? and startDate < ?",currentShiftDates.startDate.getTime(), currentShiftDates.endDate.getTime());

But it still don't work.

What I'm doing wrong?


Solution

  • I' m very sorry, it wasn't working because i was writing "startDate" and the column name is "StartDate", so the correct query was:

    fromQuery = fromQuery.where("StartDate > ? and StartDate < ?",currentShiftDates.startDate.getTime(), currentShiftDates.endDate.getTime());