I have this query but I want to change the date to delete everything that is from more than 1 hour ago based on the server time (or if not possible by server time by post date). How do I do that?
DELETE FROM wp_posts WHERE post_date < '2008-06-06 19:18:00' AND post_status = 'publish'
Here is the SQL to show latest time using now() function. Here is the SQL to get last 1 hour data in MySQL. In the above query, we select only those rows whose order_date falls within past 1 hour interval. We use INTERVAL clause to easily substract 1 hour interval from present time obtained using now() function.
SELECT convert(varchar, getdate(), 108) outputs as hh:mm:ss .
MySQL SUBTIME() FunctionThe SUBTIME() function subtracts time from a time/datetime expression and then returns the new time/datetime.
MySQL HOUR() Function The HOUR() function returns the hour part for a given date (from 0 to 838).
Use:
DELETE FROM wp_posts WHERE post_date < DATE_SUB(NOW(), INTERVAL '1' HOUR) AND post_status = 'publish'
Reference:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With