Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select data between two date range in android SQLite

I have table which contains data along with created on date. I want to select data from table according to two given date ranges, or of one particular month.

I am not sure how to do that, as created on column is of type text and is stored as dd-MM-yyyy HH:mm:ss

I am using rawQuery() to fetch data.

like image 774
Adil Bhatty Avatar asked Mar 10 '12 20:03

Adil Bhatty


1 Answers

You can do something like this:

 mDb.query(MY_TABLE, null, DATE_COL + " BETWEEN ? AND ?", new String[] {
                minDate + " 00:00:00", maxDate + " 23:59:59" }, null, null, null, null);

minDate and maxDate, which are date strings, make up your range. This query will get all rows from MY_TABLE which fall between this range.

like image 89
Tyler Treat Avatar answered Nov 07 '22 14:11

Tyler Treat