H
H
hollanditkzn2017-06-08 11:58:17
Yii
hollanditkzn, 2017-06-08 11:58:17

How to convert the date to strtotime format when sending it to the database?

I don't understand a little that when you use input type="datetime". Then when you save to the database, translate not the date, but the number of seconds elapsed.
I don’t understand exactly how only the date from the post request is taken in the controller and converted to another format

if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['view', 'id' => $model->id]);
        }

How would it be possible to call $_POST['date'] in pure php and then translate

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Fedorov, 2017-06-08
@hollanditkzn

use the timestampAttribute option in the DateValidator

C
Crash, 2017-06-08
@Bandicoot

You can use the event functionality (before saving). Write in the model:

public function beforeSave($insert)
{
    $this->date = strtotime($this->date);
    return parent::beforeSave($insert);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question