samedi 8 août 2015

deleting records form sqlite on the basis of date

In my app database there is a column which has stored date,i want to delete rows from this table where the stored date is smaller than the system's current date. I'm using the following method

      DBHelper = new DatabaseHelper(context); 
      DateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy hh:mm:ss a");
      Calendar calObj = Calendar.getInstance();
      String currentDate = dateFormat.format(calObj.getTime());
      Log.e("current date",currentDate);

      int totalRows = db.delete(DATABASE_TABLE_DAILY_ATTENDANCE, KEY_ATTENDANCE_SYN_STATUS + "= ? and " + KEY_ATTENDANCE_CREATED_DATE + " < '" + currentDate + "'", new String[] {"C"});

I'm not getting any error but this deletes all rows and I just want to delete the rows where date is smaller than the system's current date.

Aucun commentaire:

Enregistrer un commentaire