Delete entries older than 7 days
Posted: Wed May 09, 2007 2:36 am
Good day to all that help me
I would like to delete all the records in mysql database that is older than 7 days.
How do i go about selecting it in the database ( currentdate - 7) where level = '0'
my database is ctrack1
table is operator
fields is: ID,Username,Password,Date_created,Level
This is what i tried:
mysql_select_db($database_operator, $operator);
$query_delete = "DELETE FROM operator WHERE ((TO_DAYS(CURDATE()) - TO_DAYS(Date_created)) > 7) AND Level='0'";
$delete = mysql_query($query_adminlogin) or die(mysql_error());
the above code generates an error when i execute it stating that im using wrong version of MySQL. i am using for test purposes (as i know it works on my host) EasyPHP 1.8.
Then i tried the following :
$curdate = date("Y.m.d");
mysql_select_db($database_operator, $operator);
$query_cleaunup = "DELETE FROM operator WHERE '$curdate' - 'Date_created' < 7 AND Level='0'";
$cleaunup = mysql_query($query_cleaunup) or die(mysql_error());
When i execute this code it does nothing. but note that when i change the < sigh to > then it deletes all the Level 0 entries!
I just basically want to delete all the entries that is older than 7 days and is lovel 0 in my database. How do i do it? please i am desperate for an answer. I appreciate your response!
I would like to delete all the records in mysql database that is older than 7 days.
How do i go about selecting it in the database ( currentdate - 7) where level = '0'
my database is ctrack1
table is operator
fields is: ID,Username,Password,Date_created,Level
This is what i tried:
mysql_select_db($database_operator, $operator);
$query_delete = "DELETE FROM operator WHERE ((TO_DAYS(CURDATE()) - TO_DAYS(Date_created)) > 7) AND Level='0'";
$delete = mysql_query($query_adminlogin) or die(mysql_error());
the above code generates an error when i execute it stating that im using wrong version of MySQL. i am using for test purposes (as i know it works on my host) EasyPHP 1.8.
Then i tried the following :
$curdate = date("Y.m.d");
mysql_select_db($database_operator, $operator);
$query_cleaunup = "DELETE FROM operator WHERE '$curdate' - 'Date_created' < 7 AND Level='0'";
$cleaunup = mysql_query($query_cleaunup) or die(mysql_error());
When i execute this code it does nothing. but note that when i change the < sigh to > then it deletes all the Level 0 entries!
I just basically want to delete all the entries that is older than 7 days and is lovel 0 in my database. How do i do it? please i am desperate for an answer. I appreciate your response!