Hi
i would like to delete SQL data after two hours.
I've not done that before , so im wondering how this works in the database.
I currently have TIMESTAMP as a database field.
Thank you
delete SQL data .. expiration date?
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Code: Select all
$sql = "DELETE FROM mytable WHERE time<'$time_two_hours_ago'";(#10850)
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Code: Select all
WHERE DATE_SUB(CURDATE(), INTERVAL 24 HOUR)) <= time;- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
You posted this in PHP Code so I assumed that you wanted a PHP solution. What database are you using?jramaro wrote:That code snippet looks like a a command made from a webpage/ script
will that work for data already in a database?
because i want the data in a database to expire automatically after two hours.
Without having to make any query to it manually.
(#10850)
database type: MySQL database
I posted this in PHP code, because i didnt know if the command for expiration has to start with PHP on the insert SQL?
---
That snip by Jcart seems to look like what I'm tryin to find.
on DATE_SUB .. should this be a column name , or a command in SQL similar to TIMESTAMP?
Thank you
I posted this in PHP code, because i didnt know if the command for expiration has to start with PHP on the insert SQL?
---
That snip by Jcart seems to look like what I'm tryin to find.
on DATE_SUB .. should this be a column name , or a command in SQL similar to TIMESTAMP?
Thank you
- gregwhitworth
- Forum Commoner
- Posts: 53
- Joined: Tue Oct 09, 2007 1:00 am
- Location: Wasilla, Alaska