I want to format date from ‘Fri, 06/12/2015’ to ‘2015-06-12’ to save in database.
Here is my hack
if ($model->load(Yii::$app->request->post())) {
$model->mobilization_date = date('Y-m-d', strtotime($model->mobilization_date));
$model->demobilization_date = date('Y-m-d', strtotime($model->demobilization_date));
if ($model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('update', [
'model' => $model,
]);
}
is there a cleaner way to do it ?