$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."'");
这是我的代码,以获取上周的医生姓名和本周日期的数量(这意味着今天从上周开始) 它不工作??
和上个月的功能一样吗?
在我的数据库中,我使用此leads_date
字段作为时间戳
答案 0 :(得分:1)
您可以使用mysql的date_sub
函数
获取上周的所有记录
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()
答案 1 :(得分:0)
试
$daynumber = date('N', date('d'));// getting today day number
$prevweek = $daynumber+7; // starting from prev week
echo $prevdate = strtotime('-'.$prevweek.' days'); // prev week date
echo strtotime("-1 month"); // last month