I\'m using this php to fetch data from my mysql database:
$wpdb->get_var(\"select count(*) from \" . $wpdb->prefix . \"newsletter where status=\'C\'\")
Try this in your query:
select count(*) from " . $wpdb->prefix . "newsletter where status='C'
AND DATE(created)>=DATE_SUB(CUR_DATE, INTERVAL 30 DAY)
$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
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.