I have a database in that there are two column start and end. start and end are in DD.MM.YYYY format.
I have a date which is also in DD.MM.YYYY format. How
Use this below code. It will return number of days between two dates. Date are in format YYYY-MM-DD
YourDatabse database=new YourDatabse (getApplicationContext(), 1);
SQLiteDatabase sqlite=database.getReadableDatabase();
Cursor fetch=sqlite.rawQuery("SELECT julianday('"+date2+"') - julianday('"+date1+"')", null);
fetch.moveToFirst();
sqlite.close();
int noOfDays=fetch.getInt(0);
As Jon Skeet wrote, you should have stored the dates in yyyy-mm-dd
format.
However, it might be possible to convert your date values into proper date values on the fly by reordering the fields (if the fields in the string have a fixed length):
SELECT *
FROM MyTable
WHERE '2013-03-11' BETWEEN substr(StartDate, 7, 4) || '-' ||
substr(StartDate, 4, 2) || '-' ||
substr(StartDate, 1, 2)
AND substr(EndDate, 7, 4) || '-' ||
substr(EndDate, 4, 2) || '-' ||
substr(EndDate, 1, 2)