SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd",Locale.US);
Calendar cd = Calendar.getInstance();
Calendar removeBefore = Calendar.getInstance();
removeBefore.set(cd.get(Calendar.YEAR), cd.get(Calendar.MONTH),(cd.get(Calendar.DAY_OF_MONTH) - 7));//Here set day before old data to be removed.
try{
sqlDatabase=getSqlWritable();
rowaffeted=sqlDatabase.delete(TB3, TB3_Date +" < ? ", new String[]{df.format(removeBefore.getTime())});
}catch(Exception e){
e.printStackTrace();
}
//你需要使用下面的方法
public SQLiteDatabase getSqlWritable(){
if(dbhelper == null)
dbhelper=new DbOpenHelper(context, DATABASE_NAME, null, DATABASE_VERSION);
return dbhelper.getWritableDatabase();
}