Re: Delete after 30 Days

From: Date: Tue, 11 Nov 2003 01:53:51 +0000
Subject: Re: Delete after 30 Days
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-169111@lists.php.net to get a copy of this message
Dimitri Marshall wrote:
Hey, 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 Assuming it uses epoch timestamps .... you could do the following
|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 |

« previous php.general (#169111) next »