Sql query to select from 1 hour ago?

前端 未结 3 914
我在风中等你
我在风中等你 2020-12-13 17:02

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 da

相关标签:
3条回答
  • 2020-12-13 17:37

    Subdate function works too!

    SELECT subdate(current_timestamp, interval 1 hour)
    
    0 讨论(0)
  • 2020-12-13 17:41

    Use:

    DELETE FROM wp_posts
     WHERE post_date < DATE_SUB(NOW(), INTERVAL 1 HOUR)
       AND post_status = 'publish'
    

    Reference:

    • DATE_ADD
    • DATE_SUB
    0 讨论(0)
  • 2020-12-13 17:58

    Or even simpler:

    SELECT NOW() - INTERVAL 1 HOUR;
    

    So the query becomes:

    DELETE FROM wp_posts
     WHERE post_date < NOW() - INTERVAL 1 HOUR
       AND post_status = 'publish'
    
    0 讨论(0)
提交回复
热议问题