Search code examples
phpmysqlcodeigniterphpactiverecordactive-record-query

How to query sql with active record for dates between specified times


I have a database that I want to pull only certain rows that have dates in specified ranges. I'm not sure how to do this properly in active record. Right now it looks like I'm running a standard mysql query inside of an active record query. I hope this gives you the idea of what I'm looking for.

I would also like to be able to get rows with anything before today, including today and 3 days in the future.

$query = $this->db->query("SELECT * FROM 'topics_list' . 'topic date' WHERE DATE(order_datetime) BETWEEN '2012-10-01' AND '2012-10-3'");

Solution

  • this is the way . but according to the DATE format you have in the database you have to change 2012-10-01 and 2012-10-03

    $this->db->select('*');
    $this->db->from('topics_list');
    $this->db->where('order_datetime <','2012-10-03');
    $this->db->where('order_datetime >','2012-10-01');
    
    $result = $this->db->get();