HaOx
HaOx

Reputation: 1879

Android SQLite filter data with date ranges

I have an cursor that fills the list with values from SQLite table.

In the table I have one column of type text which contain date.

I want to filter the values from the table in range of dates.

Right now I'm doing it in this way, but it is not working:

cursor = sqliteDatabase.query("Servicios", null,
            "fechaservicioprevista > '01/06/2012' AND fechaservicioprevista < '01/07/2013', null, null,
            null, null);

It does not displaying any values, but there are some values in this range of dates.

Thanks.

Upvotes: 1

Views: 1922

Answers (2)

Mohamed_AbdAllah
Mohamed_AbdAllah

Reputation: 5322

Try forcing data entry to the table in the format you are comparing to. I mean you must enter 01/06/2012 not 1/6/2012. I faced similar situation and when I forced data entry to the DB to be in the format 01/06/2012, comparison worked.

Upvotes: 1

koleanu
koleanu

Reputation: 495

you should use clause 'between' and strftime() function

 strftime(%s, date) BETWEEN strftime(%s, start_date) AND strftime(%s, end_date)

Upvotes: 1

Related Questions