DateExpiry in Sqlite3 Python
If the format of the column date
is DD-MM-YYYY
, first you must change it to YYYY-MM-DD
, because this is the only valid format for SQLite:
UPDATE medicine SET date = SUBSTR(date, -4) || '-' || SUBSTR(date, 4, 2) || '-' || SUBSTR(date, 1, 2);
and then use the function DATE()
to get the rows where date
is between now and now + 30 days:
SELECT date FROM medicine WHERE date BETWEEN DATE('now') AND DATE('now', '+30 day')