Home > Blockchain >  How to query to return data range between start_date and end_date?
How to query to return data range between start_date and end_date?

Time:01-07

So, I have a view report display that filters Period From and Period To, as shown below: enter image description here

And, I have employee data with dates like this:

enter image description here

When I display the report, the date range data is unreadable. It should show up because start_date is on January 17th and end_date is on January 21st..

enter image description here

This is my query, please help.. thanks.

 ->select("a.id, a.employee_id, a.employee_name, a.leave_name, a.start_date, a.end_date, a.status, 
           b.id, b.employee_id, b.job_title_name, b.employment_status_name")
  ->join('hr_employee b', 'a.employee_id = b.employee_id', 'left')
  ->where("(a.start_date <= BETWEEN '$data[from]' AND '$data[to]') OR (a.end_date >= BETWEEN '$data[from]' AND '$data[to]')");
   return $this->db->get('hr_leaves a');

->where("(a.start_date <= BETWEEN '$data[from]' AND '$data[to]') OR (a.end_date >= BETWEEN '$data[from]' AND '$data[to]')");

CodePudding user response:

From <= End_Date AND To >= Start_Date, where From/To are user data, and [Start/End]_Date are the table columns.

  •  Tags:  
  • Related