Re: Delete after 30 Days
| From: | David T-G | Date: | Tue, 11 Nov 2003 01:18:24 +0000 |
| Subject: | Re: Delete after 30 Days | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-169117@lists.php.net to get a copy of this message | ||
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) davidtg@justpickone.org * society and not sufficient moral courage.
(work) davidtgwork@justpickone.org -- Mary Baker Eddy, "Science and Health"
http://justpickone.org/davidtg/ Shpx gur
Pbzzhavpngvbaf Qrprapl Npg!