Get from database but only last 30 days

后端 未结 3 1390
余生分开走
余生分开走 2020-12-21 22:10

I\'m using this php to fetch data from my mysql database:

$wpdb->get_var(\"select count(*) from \" . $wpdb->prefix . \"newsletter where status=\'C\'\")         


        
3条回答
  •  暖寄归人
    2020-12-21 23:06

        $wpdb->get_var("select count(*) from " . $wpdb->prefix . "newsletter where status='C'
     AND DATEDIFF(CURDATE(), created) <= 30"); ?>
    

    Used:

    DATEDIFF() - returns expr1 – expr2 expressed as a value in days from one date to the other. expr1 and expr2 are date or date-and-time expressions. Only the date parts of the values are used in the calculation.

    And:

    CURDATE() - Current date

提交回复
热议问题