Timestamp values

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mzfp2
Forum Contributor
Posts: 137
Joined: Mon Nov 11, 2002 9:44 am
Location: UK
Contact:

Timestamp values

Post by mzfp2 »

Hi

One of my tables has a timestamp which identifies the time and date the record was inserted into the database (timestamp is PHP Generated).

I require to delete records that are one month old everytime the table is accessed, just wondering, how can I calculate this?

Anything would help here

Many thanks

Muzz
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

This should do it:

Code: Select all

<?PHP
$prev_month = strtotime("-1 month");
$query = "DELETE FROM my_table WHERE timestamp < '$prev_month'";
?>
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply