0

I have an SQLite table and I want to run a query at the end of each month to delete a row from the table, is there a way to do so?

barasingha
  • 121
  • 1
  • 6
  • 1
    use workmanger and schedule a task every 30 days. https://stackoverflow.com/questions/53901179/android-work-manager-how-to-enqueue-jobs-once-a-month – akshay_shahane Feb 02 '21 at 07:05

1 Answers1

0

To delete a row just use:

    db.delete(String table, 
            String whereClause, 
            String[] whereArgs)

ex.

    db.delete("yourTable", "yourRow", null);

https://developer.android.com/reference/android/database/sqlite/SQLiteDatabase#delete(java.lang.String,%20java.lang.String,%20java.lang.String[])

Now to recognize the day of the month use Calendar class:

Calendar calendar = Calendar.getInstance();
int dayOfTheMonth = calendar.get(Calendar.DAY_OF_MONTH);

https://developer.android.com/reference/java/util/Calendar#DAY_OF_MONTH

Peppinhood
  • 39
  • 9