Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'");
like image 723
michael Avatar asked Aug 24 '12 01:08

michael


2 Answers

You can specify you $where and use active records

$this->db->group_start()
          ->or_where("product_order.generate_date >= ","$start_date")
          ->or_where("product_order.generate_date <","$end_date + INTERVAL 1 DAY")
          ->group_end();
like image 127
Usman Zia Avatar answered Oct 18 '22 09:10

Usman Zia


You can specify you $where and use active records

$where = "DATE(order_datetime) BETWEEN '2012-10-01' AND '2012-10-3'";
$this->db->where($where)->get('table_name');
like image 27
Alireza Avatar answered Oct 18 '22 08:10

Alireza