2017-07-21 30 views
0

我正在检索两个日期范围之间的数据,并且我也获取记录,但是当我选择开始日期与结束日期相同时,即使我在数据库表中记录了该日期,但只有那些记录具有不同的时间,它才会给出空白。如果有人知道解决方案,请让我知道。以下是我的查询来获取日期范围之间的记录。 在此先感谢。如何在PHP codeingiter中的两个日期之间检索数据?

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

回答

1

,你还需要指定两个日期

$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(); 
+0

非常感谢你的工作! – user7596840

+0

最受欢迎@ user7596840 –

0

试试这个

$this->db->query("SELECT * FROM transaction_tbl WHERE user_id = '$user_id' && date BETWEEN '$startDate' AND '$endDate'"); 
+0

感谢提示答案,但即使它不取记录 – user7596840

+0

$ ENDDATE1 =日期( “Y-M-d” 的strtotime( “+ 1日”,的strtotime($结束日期))); –

+0

then $ this-> db-> query(“SELECT * FROM transaction_tbl WHERE user_id ='$ user_id'&& date BETWEEN'$ startDate'AND'$ endDate1'”); –

0
$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(); 
0

在模型试试这个之间的时间。

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(); 
} 
相关问题