Welcome Guest, Not a member yet? Register   Sign In
CRUD: Select from Date Range
#1

[eluser]Unknown[/eluser]
I was hoping someone could point me in the right direction with this snippet of code. I'm trying to pull a specific date range from a database.

Here is my code snippet...

Model:
Code:
$code = $this->session->userdata('code');
$start_date = $this->input->get_post('start_date');
$end_date = $this->input->get_post('end_date');

$query = $this->db->where('code', $code )->where('request_date >=', $start_date)->where('request_date >=',$end_date)->get( 'dispatch' );
        
            if( $query->num_rows() > 0 ) {
                return $query->result();
            } else {
                echo "No records found...";
                return array();
            }

Currently it grabs the records but ignores the date ranges completely. Any help would be greatly appreciated!
#2

[eluser]crikey[/eluser]
I'm not sure exactly how to solve your problem, but some things that might be worth trying:

1. Shouldn't the operator be <= for the $end_date comparison?
2. Are the date formats for the get/post vars the same as what's being stored in the DB?
3. Try converting $start_date and $end_date to int types (I think PHP does this implicitly though)
4. Output the last query and see if it is what you expect it to be (using $this->db->last_query())

Hope that helps Smile

Cheers,
Grant
#3

[eluser]Dennis Rasmussen[/eluser]
What crikey said:
Both your date comparisons are the same.




Theme © iAndrew 2016 - Forum software by © MyBB