【问题标题】:Query to datetime field with date condition only in cakephp仅在 cakephp 中查询具有日期条件的日期时间字段
【发布时间】:2013-10-22 11:06:15
【问题描述】:

在 cakephp 查询条件中,我只有满足表的 datetime 字段条件的日期。假设我只有日期(2013-09-21)并且字段是(2013-09-21 07:45:23)。我有问题在这里给出条件。

【问题讨论】:

    标签: cakephp cakephp-2.0


    【解决方案1】:

    如果@Aryan 的解决方案不起作用,因为您需要在数据库中进行格式之间的转换,那么您需要使用 MySQL 函数DATE。这会将查找示例更改为:

    $row = $this->Model->find('all',
                        array('fields' => array('........'),
                        'conditions' => array(
                            'DATE(Story.created) >' => $date)));
    

    【讨论】:

      【解决方案2】:
      $date_string = "2013-09-21";
      $new_date = date('Y-m-d H:i:s', strtotime($date_string));
      $row = $this->Model->find('all',
                          array('fields' => array('........'),
                          'conditions' => array(
                              'Story.created >' => $new_date)));
      

      【讨论】:

        猜你喜欢
        • 2019-08-18
        • 2018-05-31
        • 1970-01-01
        • 1970-01-01
        • 2011-05-30
        • 1970-01-01
        • 2016-07-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多