I want to delete all rows older than 5 days, in my table.
My table have a createdOn column of type date can u suggest me the query.
I m using mySql database
now i wrote folloiwng query
SELECT * from `user_games` where created_on >= DATE_SUB(created_on, INTERVAL 5 DAY)
to see the user_games which are five days old
but always im getting same result even when i run query for Invterval 1 Day or Interval 5 day
while today curdate is 2011-5-2
Try this,
delete from mytable where datediff(now(), mytable.date) > 5
This would be proper approach to delete.
Use date_sub function like:
delete from `myTable` where createdOn<DATE_SUB(curdate(), INTERVAL 5 DAY);
You want to do this:
delete from myTable
where createdOn < CurDate() - 5
DELETE FROM table_name WHERE time
< (NOW() - INTERVAL 5 DAYS)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.