addBetweenCondition今天没有返回

时间:2014-08-07 11:04:07

标签: php yii

我尝试了几种方法。它没有返回正确的数字。它要么给出我在开头设置的默认号码,要么返回搜索的条件但忽略store_id。

        $percent = 8;
        $today = date('Y-m-d');

        $criteria = new CDbCriteria();
        $criteria->compare('store_id', 253);
//      $criteria->condition = 'store_id=:store_id';
//      $criteria->params = array('store_id'=>253);
//      the bottom addcondition ignores that store id, and gives me what it finds btwn dates
//      $criteria->addCondition = 'CURRENT_DATE BETWEEN date_from AND date_to'; 
//      addbetweencondition doesn't find anything between dates
        $criteria->addBetweenCondition($today, 'date_from', 'date_to');
        $override = Model::model()->find($criteria);
        if ($override) {
            $override_percent= $override->percent/100;
        }
        print_r ($override_percent);

1 个答案:

答案 0 :(得分:0)

您使用addBetweenCondition错误。前三个参数应为:

  • 要匹配的列
  • 开始日期
  • 结束日期

我认为它应该类似于下面的代码(未经测试):

$date_from = date('Y-m-d');
$date_to = date('Y-m-d 23:59:59');
$criteria->addBetweenCondition('column_name_that_contains_date', $date_from, $date_to);

阅读有关该功能的更多信息: http://www.yiiframework.com/doc/api/1.1/CDbCriteria#addBetweenCondition-detail