【发布时间】:2014-03-09 15:21:08
【问题描述】:
我无法使用 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}".'),
提前感谢您的帮助
【问题讨论】: