Ashish Augustine
Ashish Augustine

Reputation: 2030

Sort a list in ascending order by date from sqlite

I am having a code for retrieving data like this. I wanted to get records with the dates in the ascending order.I tried using "KEY_DATE_TIME ASC" . but it didnt work.

public Cursor fetchAllReminders() {

return mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_TITLE,
        KEY_BODY, KEY_PHONE,KEY_DATE_TIME}, null, null, null, null, null);
}

Upvotes: 12

Views: 23834

Answers (1)

Steve Bergamini
Steve Bergamini

Reputation: 14600

Assuming that KEY_DATE_TIME is a String constant holding the name of the db field, the following should work:

return mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_TITLE,
        KEY_BODY, KEY_PHONE,KEY_DATE_TIME}, null, null, null, null, KEY_DATE_TIME + " ASC");

Upvotes: 41

Related Questions