[PHP] Delete after 30 Days

2003-11-10 Thread Dimitri Marshall
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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Delete after 30 Days

2003-11-10 Thread Rolf Brusletto
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
|
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Delete after 30 Days

2003-11-10 Thread David T-G
Dmitri --

...and then Dimitri Marshall said...
% 
% Hey,
% Here's my situation. I'm making a message board and I want posts to be
% deleted after 30 days.

OK.


% 
% 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.

1) This should probably be handled through cron so that a) it gets done
regularly and b) it doesn't get overdone.  Once you figure out how to
use 2) or 3) or something else, put the command(s) in a script and call
it once a day.

2) If, like Rolf, we assume that you have an epoch timestamp on each
entry, then just subtract 2592000 seconds from your current timestamp and
delete anything older (smaller) than that.

3) If you use date or datetime columns for your entries, then you can let
mysql do the math for you with something like

  delete from table where date  date_sub(now(),interval 30 days) ;

or so (untested).

For more info, check the mysql manual.


% 
% Dimitri Marshall


HTH  HAND

:-D
-- 
David T-G  * There is too much animal courage in 
(play) [EMAIL PROTECTED] * society and not sufficient moral courage.
(work) [EMAIL PROTECTED]  -- Mary Baker Eddy, Science and Health
http://justpickone.org/davidtg/  Shpx gur Pbzzhavpngvbaf Qrprapl Npg!



pgp0.pgp
Description: PGP signature