Get from database but only last 30 days

后端 未结 3 1397
余生分开走
余生分开走 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:07

    There is affffdate() function in MySQL wich you can use for this :)

    $wpdb->get_var("select count(*) from " . $wpdb->prefix . "newsletter where status='C' and date_format(created,'%Y%m%d')>date_format(affffdate(now(),interval -30 day),'%Y%m%d')");
    

    This one is for 30 days back but you can replace the "interval -30 day" with "interval -1 month" or visit dev.mysql where you have all explained.

    Hope it helps.

提交回复
热议问题