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."'");

this is my code to get last week leads count from table doctor name and where date with in this week (means today is thusday then start from previous week) it not working??

and have do same for function like last month ??

in my db i use this leads_date field as timestamp

papa.ramu
  • 423
  • 1
  • 5
  • 18

2 Answers2

1

you can use the date_sub function from mysql

get all records from last week

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()

get all records from last month

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()

ins0
  • 3,918
  • 1
  • 20
  • 28
0

try

$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

For more :- Getting last month's date in php

day of the week to day number (Monday = 1, Tuesday = 2)

Community
  • 1
  • 1
Rakesh Sharma
  • 13,680
  • 5
  • 37
  • 44