top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration
Print Preview

How to delete old records in my MySql database?

0 votes
59 views

I wish to delete records in my database that is older than 3 months.

$todays_date = date('Y-m-d');
$old_records_to_delete = ???

if($old_records_to_delete)
{
include(connect.php);
$sql = "DELETE FROM table WHERE date >= '$old_records_to_delete'";
mysql_query($sql, $connect_db) or die(mysql_error());
}

posted Aug 2, 2013 by Deepak Dasgupta

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

3 Answers

+1 vote
 
Best answer

$query = "DELETE FROM __table_name__ WHERE __date__ < NOW() - INTERVAL 3 MONTH"

answer Aug 2, 2013 by Jagan Mishra
+1 vote

$query = "DELETE FROM __table_name__ WHERE __date__ BETWEEN NOW() - INTERVAL 3 MONTH AND NOW()"

answer Aug 2, 2013 by Sheetal Chauhan
0 votes

Try something like:

$oldDate = new DateTime();
$oldDate->sub(new DateInterval('P3M'));
$old_records_to_delete = $oldDate->format('Y-m-d');

answer Aug 2, 2013 by Abhay Kulkarni
Similar Questions
+1 vote

I have some problem
I have store the data in the database without encrypt but i am view the data encrypt method after 1 day and doesn't know the details.

I am using php and mysql, Could the experts please comment on this, and offer some advice?

+3 votes

I have started learning PHP and got a thought about mysql.

I did google and found this stack overflow link
http://stackoverflow.com/questions/625930/what-is-the-maximum-size-of-a-mysql-database-in-version-5-and-up

But there are less answers and more discussions. Can someone give me the right answer which has full description in it.


Useful Links with Similar Problem
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#470/147, 3rd Floor, 5th Main,
HSR Layout Sector 7,
Bangalore - 560102,
Karnataka INDIA.
QUERY HOME
...