I Want to delete some records before a certain date. When i execute the following statements: DELETE FROM 'client_update_history' WHERE DATE(date_history) < '2015/11/01'
i get a error. date_history is a DateTimeField;
I Want to delete some records before a certain date. When i execute the following statements: DELETE FROM 'client_update_history' WHERE DATE(date_history) < '2015/11/01'
i get a error. date_history is a DateTimeField;
Seems you do not have correct date format. The correct mysql format is yyyy-MM-dd
DELETE FROM client_update_history WHERE DATE(date_history) < '2015-11-01'
Do note that if you are using date_history
as an index you are better of doing
DELETE FROM client_update_history WHERE date_history < '2015-11-01'
so that this index can be used.
You have to include the time as well, using this format: YYYY-MM-DD HH:MM:SS
DELETE FROM 'client_update_history' WHERE DATE(date_history) < '2015/11/01 00:00:00'
You'd better convert '2015/11/01' to date as well: STR_TO_DATE('2015/11/01', '%Y/%m/%d'). By doing this, you're informing mysql how to parse the date you want to use.