当前日期和当前日期+ 1个月

时间:2014-03-09 15:21:09

标签: php mysql datetime yii

我无法使用Yii在mysql中保存日期和时间。

我的表包含(在Mysql表中定义的其他字段)

   fromDate datetime
    toDate datetime
    create datetime
    modified datetime

在我添加fromDatetoDate

之前一直有效

在我的模型中,在beforeValidate方法中,我有以下几行

if ($this->isNewRecord) {
            $this->created = new CDbExpression('NOW()');
            $this->fromDate = new CDbExpression('NOW()');
            $this->toDate = new CDBExpression('NOW()+ INSTANCE 1 MONTH');
} else {
            $this->modified = new CDbExpression('NOW()');
        }
        return parent::beforeValidate();
    }

我收到错误From Date的格式无效。

我必须在我的规则中添加,我检查toDate是否大于fromDate

array('toDate','compare','compareAttribute' => 'fromDate','operator'=>'>', 'allowEmpty'=>'false', 'message' => '{attribute} should be greater than "{compareValue}".'),

提前感谢您的帮助

1 个答案:

答案 0 :(得分:0)

我发现删除规则

array('fromDate', 'date'),

它有效,

抱歉这个问题