Codeigniter 如何在PHP codeingiter中检索两个日期之间的数据?

Codeigniter 如何在PHP codeingiter中检索两个日期之间的数据?,codeigniter,Codeigniter,我正在检索两个日期范围之间的数据,我也在获取记录,但当我选择“开始日期”和“结束日期”时,即使我在数据库表中有该日期的记录,也会显示为空,只有这些记录具有不同的时间。如果有人知道解决方案,请让我知道。下面是我在日期范围之间获取记录的查询。 提前谢谢 $this->db->select('*'); $this->db->from('transaction_tbl'); $this->db->where('user_id',$user_id);

我正在检索两个日期范围之间的数据,我也在获取记录,但当我选择“开始日期”和“结束日期”时,即使我在数据库表中有该日期的记录,也会显示为空,只有这些记录具有不同的时间。如果有人知道解决方案,请让我知道。下面是我在日期范围之间获取记录的查询。 提前谢谢

$this->db->select('*');
    $this->db->from('transaction_tbl');
    $this->db->where('user_id',$user_id);
    $this->db->where('date >=',$startDate);
    $this->db->where('date <=',$endDate); 
    $query = $this->db->get();
$this->db->select('*');
$this->db->from('transaction_tbl');
$this->db->where('user\u id',$user\u id);
$this->db->where('date>=',$startDate);
$this->db->where('date试试这个

$this->db->query("SELECT * FROM transaction_tbl WHERE user_id = '$user_id' && date BETWEEN '$startDate' AND '$endDate'");
$this->db->select('*');
$this->db->from('transaction_tbl');
$this->db->where('user\u id',$user\u id);
$this->db->where('date=',$endDate);
$query=$this->db->get();

您还需要指定两个日期之间的时间

$startDate=date("Y m d",strtotime($startDate)).' 00:00'; //00:00 start day time
$endDate=date("Y m d",strtotime($endDate)).' 23:59'; //23:59 end day time
$this->db->select('*');
$this->db->from('transaction_tbl');
$this->db->where('user_id',$user_id);
$this->db->where('date >=',$startDate);
$this->db->where('date <=',$endDate); 
$query = $this->db->get();
$startDate=date(“Y-m-d”,strottime($startDate)).“00:00”;//00:00开始日期时间
$endDate=date(“Y-m-d”,strotime($endDate)).“23:59”;//23:59结束一天的时间
$this->db->select('*');
$this->db->from('transaction_tbl');
$this->db->where('user\u id',$user\u id);
$this->db->where('date>=',$startDate);
$this->db->where('date
在你的模型中试试这个


感谢您提出答案,但即使它没有获取记录$endDate1=date(“Y-m-d”,strotime(+1天),strotime($endDate));然后$this->db->query(“从事务中选择*,其中user_id=“$user_id”&&date在“$startDate”和“$endDate1”之间);
$startDate=date("Y m d",strtotime($startDate)).' 00:00'; //00:00 start day time
$endDate=date("Y m d",strtotime($endDate)).' 23:59'; //23:59 end day time
$this->db->select('*');
$this->db->from('transaction_tbl');
$this->db->where('user_id',$user_id);
$this->db->where('date >=',$startDate);
$this->db->where('date <=',$endDate); 
$query = $this->db->get();
function your_model($user_id,$startDate,$endDate){
$query=$this->db->query("SELECT * FROM transaction_tbl WHERE user_id = 
$user_id && date BETWEEN $startDate AND $endDate");
return $query->result_array();
}