Hi,
I am inserting date in the database.Now I want to query the date for the last 7 days and get all the names which have been added in the last 7 days. How can I achieve that?
[HIGH]public static final String KEY_ROWID = "_id";
public static final String KEY_NAME ="persons_name";
public static final String KEY_DATE = "current_date";
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" +
KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
KEY_DATE + " TEXT NOT NULL, " +
KEY_WANDERING + " TEXT NOT NULL);"
);
}
[/HIGH]
//to insert data in database
[HIGH]ContentValues cv = new ContentValues();
cv.put(KEY_DATE, System.currentTimeMillis());
cv.put(KEY_NAME , name);
[/HIGH]
//I am trying to query date for the last 7 days
[HIGH]String[] columns = new String[]{KEY_ROWID, KEY_NAME};
String result =" ";
long sevenDays = System.currentTimeMillis() - 1000 * 60 * 60 * 24 * 7L;
Cursor c = ourDatabase.query(DATABASE_TABLE, null, KEY_DATE + " > "+ sevenDays, null, null, null, null);
int iRow = c.getColumnIndex(KEY_ROWID);
int iName = c.getColumnIndex(KEY_NAME);
for(c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
result = result + c.getString(iName) + ",";
}
return result;
[/HIGH]
I am inserting date in the database.Now I want to query the date for the last 7 days and get all the names which have been added in the last 7 days. How can I achieve that?
[HIGH]public static final String KEY_ROWID = "_id";
public static final String KEY_NAME ="persons_name";
public static final String KEY_DATE = "current_date";
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" +
KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
KEY_DATE + " TEXT NOT NULL, " +
KEY_WANDERING + " TEXT NOT NULL);"
);
}
[/HIGH]
//to insert data in database
[HIGH]ContentValues cv = new ContentValues();
cv.put(KEY_DATE, System.currentTimeMillis());
cv.put(KEY_NAME , name);
[/HIGH]
//I am trying to query date for the last 7 days
[HIGH]String[] columns = new String[]{KEY_ROWID, KEY_NAME};
String result =" ";
long sevenDays = System.currentTimeMillis() - 1000 * 60 * 60 * 24 * 7L;
Cursor c = ourDatabase.query(DATABASE_TABLE, null, KEY_DATE + " > "+ sevenDays, null, null, null, null);
int iRow = c.getColumnIndex(KEY_ROWID);
int iName = c.getColumnIndex(KEY_NAME);
for(c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
result = result + c.getString(iName) + ",";
}
return result;
[/HIGH]