T
T
Tatiana Komarova2015-09-04 13:02:52
Yii
Tatiana Komarova, 2015-09-04 13:02:52

How to enter the current date in the AR YII2 model?

Actually, a question. What are the features? Search is all about formatting. And how to get the date itself?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vyacheslav, 2015-09-04
@tatia_kom

(new \DateTime('now', new \DateTimeZone('Europe/Moscow')))->format('Y-m-d H:i:s');
)))
The \DateTimeZone constructor parameter naturally differs for different zones.

A
Andrey Pavlenko, 2015-09-04
@Akdmeh

The model can write time almost automatically. To do this, read the documentation for the TimestampBehavior class. You can record the time the model was created or updated.

A
Anton, 2015-09-04
@karminski

To "put" the current date into AR, there is nothing better than:

$attributes = [
    'date' => \yii\db\Expression('NOW()')
]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question