Assuming it uses epoch timestamps .... you could do the followingHey, Here's my situation. I'm making a message board and I want posts to be deleted after 30 days.
Does anyone know of a script, or how, I can delete an entry on my database after a certain amount of time (ie. 30 days) automatically.
Dimitri Marshall
|function subtractDay($tS, $numDays){
//subtracts a day to the timstamp submitted through $timeStamp
//from phpexamples.net
$timeStamp = mktime (date <http://www.php.net/date>('H',$tS),date <http://www.php.net/date>('i',$tS),date <http://www.php.net/date>('s',$tS),date <http://www.php.net/date>('n',$tS),date <http://www.php.net/date>('j',$tS)-$numDays,date <http://www.php.net/date>('Y',$tS));
return $timeStamp;
}
$thirtyDaysPast = subtractDay(time(), 30);
$||thirtyDaysPast will be your timestamp thirty days ago, the sql would look like
DELETE from <your table here> WHERE timestamp < '$thirtyDaysPast'
Hope it helps,
Rolf Brusletto http://www.phpExamples.net |
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php