Reputation: 137
i am retrieving data between two date range and i am getting records also but when i select start date same as end date it is giving me blank even though i have record of that date in database table, only those records have different time.If anyone know solution please let me know.Below is my query to fetch records between date range. Thanks in advance.
$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();
Upvotes: 0
Views: 1925
Reputation: 71
Try this in your model.
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();
}
Upvotes: 0
Reputation: 576
you need to specify time also between two dates
$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();
Upvotes: 1
Reputation: 78
$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();
Upvotes: 0
Reputation: 337
try this
$this->db->query("SELECT * FROM transaction_tbl WHERE user_id = '$user_id' && date BETWEEN '$startDate' AND '$endDate'");
Upvotes: 0