I want to query all data between two date fields. The problem I am having is my database has a Datetime field and I only want to query the dates. I normally can get this to work with a like statement but I need to add logic and active record for like does not seem to support this. I used multiple where statements and was able to get this to work by adding "+1days to the to_date field. It seems to work but I don't like it and wonder if there is a better way to go about this. If I dont add the +1 days to my code it only return the < and > and does not return any rows where field = date. Hopefully this makes sense.
I have tried the below code and it does not return anything where date = myInput.
$query = $this->db->select('*')->from('t_clock_punch')
->where('clock_in >=',date("Y-m-d", strtotime($fromDate)))
->where('clock_in <=', date("Y-m-d", strtotime($toDate)))
->get();
return $query->result_array();
}
I just added a day to my ->where clause and it seems to work just not sure if this is correct and may be problematic later on.
->where('clock_in <=', date("Y-m-d", strtotime($toDate . '+1 days')))