Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting data posted in between two dates

How can I retrieve data from the database by querying records between two dates using CodeIgniter's activerecord?

like image 569
Thomas John Avatar asked Feb 02 '11 14:02

Thomas John


People also ask

Can we use between for dates in SQL?

The SQL BETWEEN Operator The BETWEEN operator selects values within a given range. The values can be numbers, text, or dates. The BETWEEN operator is inclusive: begin and end values are included.

How do I select a specific date range in SQL?

SELECT * FROM PERSONAL WHERE BIRTH_DATE_TIME BETWEEN '2001-03-01 11:00:00' AND '2005-03-01 22:00:00';


2 Answers

This looks like what you need:

$this->db->where('order_date >=', $first_date); $this->db->where('order_date <=', $second_date); return $this->db->get('orders'); 
like image 100
Teej Avatar answered Sep 22 '22 02:09

Teej


Try This:

$this->db->where('sell_date BETWEEN "'. date('Y-m-d', strtotime($start_date)). '" and "'. date('Y-m-d', strtotime($end_date)).'"'); 

Hope this will work

like image 45
Chakradhar Avatar answered Sep 20 '22 02:09

Chakradhar