user7596840
user7596840

Reputation: 137

How to retrieve data between two dates in PHP codeingiter?

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

Answers (4)

dipti
dipti

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

Kundan Prasad
Kundan Prasad

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

Jaydeep Dobariya
Jaydeep Dobariya

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

Akshit Ahuja
Akshit Ahuja

Reputation: 337

try this

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

Upvotes: 0

Related Questions