【问题标题】:Kohana ORM select records by dateKohana ORM 按日期选择记录
【发布时间】:2015-07-17 16:03:46
【问题描述】:

我需要使用 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();

提前致谢!

【问题讨论】:

    标签: mysql date orm kohana


    【解决方案1】:

    您可能希望使用如下的 between 查询:

    $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();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-28
      • 2020-08-22
      • 2023-04-02
      • 2012-03-08
      • 1970-01-01
      • 2014-10-19
      • 1970-01-01
      相关资源
      最近更新 更多