MySQL query to get data in WordPress Php base on numbers of exact days from Current

i want to get the ID from the post table where the post_modified date is exactly 5day ago. and foreach ID i get i will do another call another function. i know i have to add a loop somewhere but mybrains hurts when it comes to looping please help!

i have 3 example records to compare date.

Read More
{
status: "ok",
post: [
{
ID: "99",
post_modified: "2015-09-02 07:58:14"
},
{
ID: "100",
post_modified: "2015-09-04 02:59:27"
},
{
ID: "101",
post_modified: "2015-09-09 07:36:56"
}
]
}

this is myfunction code

public function test(){
            global $wpdb;
            $data= $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE post_status like 'wc-completed' AND post_modified < DATE_SUB(now(), INTERVAL 5 DAY)");

            return $data;

        }

Related posts

1 comment

  1. ok i solved it for getting correct data base on 5 day interval

    $data= $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE post_status like 'wc-completed' AND DATE_SUB(CURDATE(),INTERVAL 5 DAY) <= post_modified");
    

Comments are closed.