Yii2:日期保存默认时间'1970-01-01 00:00:00'

时间:2015-04-02 17:09:57

标签: php mysql date yii2

我的验证规则设置如下:

[['service_start_time', 'service_end_time'],'default','value'=>Null],
[['service_start_time', 'service_end_time'],'date','format' => 'php:d-M-Y H:i a'],

和功能

public function beforeSave($insert) {

    $mytime = date("Y-m-d H:i:s", strtotime($this->date_time));
    $service_start_time= date("Y-m-d H:i:s", strtotime($this->service_start_time));
    $service_end_time= date("Y-m-d H:i:s", strtotime($this->service_end_time));

        $this->date_time = $mytime;
        $this->service_start_time = $service_start_time;
        $this->service_end_time = $service_end_time; 

        return parent::beforeSave($insert);

    }  

为什么我在'1970-01-01 00:00:00'设置为default

的规则中以Null格式保存日期的原因

1 个答案:

答案 0 :(得分:-1)

请将service_time_start中的日期值格式更改为Y-m-d而不是d-m-y ..可以解决您的问题