tags:

views:

60

answers:

3

I need to delete uploaded files from the server after 15 days using SQL.

How would I do that? The following is the current code, but it isn't working.

<?php
$con = mysql_connect("localhost","mt","mt");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("mt", $con);

function curdate(){
date_default_timezone_set ("Asia/Calcutta"); 
$cd=date("d/m/Y");
}

mysql_query("DELETE FROM mt_upload WHERE DateTime < DATE_SUB(curdate(), INTERVAL 1 DAY)
'");

mysql_close($con);
?>
A: 

Hello Mike,

You have to configure cron jobs for that........

you have cron Job in your cpanel setup that.......

configure the timestamps,

set the php file with only delete script no timestamp management.........

may be you can search for CRon job over google......

Ankit Sachan
Excessive ellipsis ftw!
Mike B
+1  A: 

I believe there may be a date / datetime mismatch in your statement which I've seen act goofy under MySQL. Try to match date comparison with dates and datetime comparisons with datetime.

Try using now() instead of curdate() and see if you get better behavior.

"DELETE FROM mt_upload WHERE DateTime < DATE_SUB(now(), INTERVAL 15 DAY)"

Eric Holmberg
hmmm thank u very much its working fine for now()....how can i use with curdate() because i want date format in this way for some other work 21/11/2009 in now function date format in this way 2009/11/21
Lavanya ks
A: 

This query looks more clear and does not use date functions which seem to confuse many people:

DELETE FROM mt_upload WHERE DateTime <= CURRENT_TIMESTAMP - INTERVAL 15 DAY
Salman A