問題描述
我有一個數據庫,我只想提取日期在指定范圍內的某些行.我不確定如何在活動記錄中正確執行此操作.現在看起來我正在活動記錄查詢中運行標準的 mysql 查詢.我希望這能讓你知道我在尋找什么.
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.
我還希望能夠獲取包含今天之前的任何內容的行,包括今天和未來 3 天.
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'");
推薦答案
這就是方法.但根據您在數據庫中的 DATE 格式,您必須更改 2012-10-01
和 2012-10-03
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();
這篇關于如何使用活動記錄查詢指定時間之間日期的sql的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!