Search code examples
mysqlheidisql

How to convert this stored procedure to retain or delete data from past 7 days


Where IFNULL(d.updated,d.inserted) < (CONCAT(YEAR(NOW()), "",MONTH(NOW)), "", "01") -INTERVAL ',date_logs,' DAY):"):

Question : I need to create a stored procedure that cab delete data from past 7 days the above codes is for 30 days only .please help im just new to sql thank you.


Solution

  • The secret is in the usage of NOW() (converted to date to remove the current time of the day) and removing 7 days with interval '7 DAY'

    the where condition should be similar to

    Where IFNULL(d.updated,d.inserted) < NOW()::date - interval '7 DAY';