Fat Galah NewsFat Galah NewsFat Galah BlogFat Galah Client LoginFat Galah Client Contact Details
Fat Galah Internet Design Studios
103 Burrendah Road, Jindalee, QLD

Local call: 1800 99 33 99 (Australia Only)
International Ph: +61 7 3715 5999
Ph: 07 37155999

MYSQL Delete item after a set number of days or months

November 23rd, 2009

If you are looking for a delete MYSQL functions to remove items after a set number of days, one of the easiest is the following example.

How this works. OK date_added is either a date or datetime field and subdate means minus this from something curdate() is the current date INTERVAL 2 day count the number of days (this can also have month and year).

Put altogether. if the date_added is less then current date minus 2 days delete it.

 $str = sprintf("DELETE FROM tableName WHERE date_added < subdate(curdate(), INTERVAL 2 day)");
 mysql_query($str) ;
 

Leave A Comment:

Name:(Required)
XHTML ValidationCSS Validation