【问题标题】:current date and current date + 1month当前日期和当前日期 + 1 个月
【发布时间】:2014-03-09 15:21:08
【问题描述】:

我无法使用 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}".'),

提前感谢您的帮助

【问题讨论】:

    标签: php mysql datetime yii


    【解决方案1】:

    我发现删除规则,

    array('fromDate', 'date'),
    

    有效,

    抱歉这个问题

    【讨论】:

      猜你喜欢
      • 2020-06-07
      • 2012-05-22
      • 2022-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多