drduh44480
2014-12-01 08:22
浏览 48
已采纳

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

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • douzhi1813 2014-12-01 08:30
    已采纳

    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.

    评论
    解决 无用
    打赏 举报
查看更多回答(2条)

相关推荐 更多相似问题