Mysql Query将在日期返回null [关闭]

hello i have this MYSQL QUERY

 public function getInvoices($data,$date1,$date2)
{
    $get = "Select count(*) as count,
              str_to_date(concat(yearweek(date),'monday'),'%X%V %W') as date,
              DATE_ADD(str_to_date(concat(yearweek(date),'monday'),'%X%V %W'),INTERVAL 6 DAY) as endDate
              FROM affilitechargebackResponse
              WHERE companyID = ".$data."
              AND date >=".$date1."
              AND date <=".$date2."
              AND process = 1
              group by yearweek(date);";
   $query = $this->db->query($get);
   return $query->result();
}

I dont know what is the reason why nothing will return even i have a data from my database. When i delete the line AND date <=".$date2." the code will return the data from db..Even i try BETWEEN still it return null

Try this it will work :

$get = "Select count(*) as count,
              str_to_date(concat(yearweek(date),'monday'),'%X%V %W') as date,
              DATE_ADD(str_to_date(concat(yearweek(date),'monday'),'%X%V %W'),INTERVAL 6 DAY) as endDate
              FROM affilitechargebackResponse
              WHERE companyID = ".$data."
              AND date >='".$date1."'
              AND date <='".$date2."'
              AND process = 1
              group by yearweek(date);";

Remove double quotes from date1 and date2. Use single quotes.

Use Dates in single quotes and try again.

$get = "Select count(*) as count,
              str_to_date(concat(yearweek(date),'monday'),'%X%V %W') as date,
              DATE_ADD(str_to_date(concat(yearweek(date),'monday'),'%X%V %W'),INTERVAL 6 DAY) as endDate
              FROM affilitechargebackResponse
              WHERE companyID = ".$data."
              AND date >='".$date1."'
              AND date <='".$date2."'
              AND process = 1
              group by yearweek(date);";
 AND date >=".$date1."
 AND date <=".$date2."

to

 AND date >='".$date1."'
 AND date <='".$date2."'