Hello,
I am building for my site (phpnuke) and e-card system.. now I'm a little stuck and I'd hoped you could help me out. The idea of following code is that all e-cards stored in database after a specific time (here 14 days) gets deleted.. well.. it's not working.. I think the problem is with the comparing of the dates in the sql-code.. all dates in the database are stored using this date("Y-m-d")
$day = date("d"); $month = date("m"); $year = date("Y"); $day = $day - 14; if($day<1){ $day = $day + 30; $month--; if ( ($month==2) and ($days>28) ) $days = 28; if($month==0){ $month = 12; $year++; } } $maxdate = $year."-".$month."-".$day; $sql = "DELETE FROM cute_ecards WHERE date<'$maxdate'"; mysql_query ($sql);
$day = date("d"); $month = date("m"); $year = date("Y");
$day = $day - 14; if($day<1){ $day = $day + 30; $month--; if ( ($month==2) and ($days>28) ) $days = 28; if($month==0){ $month = 12; $year++; } }
$maxdate = $year."-".$month."-".$day;
$sql = "DELETE FROM cute_ecards WHERE date<'$maxdate'"; mysql_query ($sql);
if your date-field is of type date or datetime you should be able to use the following statement
DELETE FROM table WHERE datecolumn < (NOW() - INTERVAL 14 DAY)
intrasting.. solution could be closer than I though.. after burning my CD I'll try it and let you know if it's working..
thanks anyway..
lolz.. your signature 😃