Harinder
Harinder

Reputation: 1257

Delete Data fom Mysql After 24hrs

hello i am working on a database where i want to delete data which is 24hrs old ...

and i am using now() to insert data ..... here is my insert code

INSERT INTO counter_ads (page,ip,time) VALUES ( '$page', '$ref', NOW())

can any one help i want if time column is old than 24hrs it should get delete ... with mysql query. i want something like

DELETE FROM counter_ads WHERE NOW()-24 > time

i know this will not work but something like this

thx

Upvotes: 2

Views: 4463

Answers (2)

juergen d
juergen d

Reputation: 204766

DELETE FROM counter_ads WHERE `time` < NOW() - interval 1 day

Upvotes: 1

eggyal
eggyal

Reputation: 125865

DELETE FROM counter_ads WHERE time < NOW() - INTERVAL 24 HOUR

You could also consider automating such a process using MySQL's event scheduler, if so desired.

Upvotes: 11

Related Questions