I
I
Ivan Lykov2018-04-20 11:08:05
Yii
Ivan Lykov, 2018-04-20 11:08:05

How to save automatically date in timestamp format in yii2?

Guys, good afternoon, question
hung class

public function behaviors()
    {
        return [
            'timestamp' => [
                'class' => TimestampBehavior::className(),
                'attributes' => [
                    ActiveRecord::EVENT_BEFORE_INSERT => 'created_at',
                    ActiveRecord::EVENT_BEFORE_UPDATE => 'updated_at',
                ],
            ],
        ];
    }

But it swears that the form is incorrect, it saves in the int type 594321564
How do I tell yii to save in the format timestamp: data time: minute: sec and so on

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Donkovtsev, 2018-04-20
@Jhon_Light

https://donkovtcev.ru/notes/yii2-date-to-time-beha...
upd: I mixed up the question, probably just need to do this:

public function behaviors()
    {
        return [
            'timestamp' => [
                'class' => TimestampBehavior::className(),
                'attributes' => [
                    ActiveRecord::EVENT_BEFORE_INSERT => 'created_at',
                    ActiveRecord::EVENT_BEFORE_UPDATE => 'updated_at'
                ],
                'value' => new Expression('NOW()')
            ],
        ];
?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question