我的验证规则设置如下:
[['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
格式保存日期的原因
答案 0 :(得分:-1)
请将service_time_start中的日期值格式更改为Y-m-d而不是d-m-y ..可以解决您的问题