2014-07-17 83 views
1
$start = strtotime('this week'); 
$results =$wpdb->get_results("SELECT count(doctor_name) AS totalleads FROM `wp-leads-count` WHERE doctor_name ='Sasanthi' and leads_date >='". $start."'"); 

這是我的代碼上週拿到導致從表中醫生名稱數量和日期的格式與本週(指今天thusday然後從上一週開始) 它不工作?如何上週和上個月日期函數比較

並且像上個月一樣做功能?

在我的分貝

我用這個leads_date字段作爲時間戳

回答

1

可以使用date_sub功能從MySQL

擺脫上週

SELECT count(doctor_name) AS totalleads FROM `wp-leads-count` WHERE doctor_name ='Sasanthi' and leads_date between date_sub(now(),INTERVAL 1 WEEK) and now()

所有記錄從上月獲得的所有記錄

SELECT count(doctor_name) AS totalleads FROM `wp-leads-count` WHERE doctor_name ='Sasanthi' and leads_date between date_sub(now(),INTERVAL 1 MONTH) and now()