我无法使用Yii在mysql中保存日期和时间。
我的表包含(在Mysql表中定义的其他字段)
fromDate datetime
toDate datetime
create datetime
modified datetime
在我添加fromDate
和toDate
在我的模型中,在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}".'),
提前感谢您的帮助
答案 0 :(得分:0)
我发现删除规则
array('fromDate', 'date'),
它有效,
抱歉这个问题