Reputation: 531
I try to create a query with a where clause which filters between dates. My query looks something like
java.util.Date date1 = ...
java.util.Date date2 = ...
where().between("datefield", date1, date2)
But it doesn't work. I am building my query with the QueryBuilder
and I use selectRaw(...)
and queryRaw(...)
. Can anyone help?
Upvotes: 3
Views: 4279
Reputation: 116908
Yeah, this isn't going to work because under Android, Date
fields are being persisted as strings which don't compare right when using SQL between
. One way to fix this would be to store your Date
fields as longs instead:
@DatabaseField(dataType = DataType.DATE_LONG)
private Date dateField;
This will store the Date
as the epoch milliseconds long number which is comparable and which will work with between
.
Upvotes: 13