Kohana ORM按日期选择记录

时间:2015-07-17 16:03:46

标签: mysql date orm kohana

我需要使用Kohana ORM获取指定日期的所有行。日期字段名称为'created_date',存储日期格式为'0000-00-00 00:00:00'('Y-m-d H:i:s')。

$day = '2015-07-17'; // for example

$items_filtered = ORM::factory($this->_object_name)
->where(DB::expr("DATE_FORMAT('created_date', '%Y-%M-%d')"), '=', $day)
->order_by('created_date', 'DESC')
->find_all();

提前致谢!

1 个答案:

答案 0 :(得分:4)

您可能希望使用如下所示的查询之间:

$dayst = '2015-07-17 00:00:00'
$dayen = '2015-07-17 23:59:59'

$items_filtered = ORM::factory($this->_object_name)
->where('created_date', 'between', array($dayst, $dayen))
->order_by('created_date', 'DESC')
->find_all();