0

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

4 Answers 4

1

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();
Sign up to request clarification or add additional context in comments.

1 Comment

Why not add the time suffixes to the first parameter of date()? select('*') never needs to be written in CodeIgniter -- it is the default. This whole script can be written with get_where() alone.
0

try this

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

3 Comments

thanks for suggesting answer but even though it is not fetching records
$endDate1 = date("Y-m-d", strtotime("+1 days", strtotime($endDate)));
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();

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.