C
C
connor742015-11-01 09:43:28
Yii
connor74, 2015-11-01 09:43:28

Am I filtering by date correctly?

Good afternoon!
It is necessary in Yii2 to display records for which the publication date ends later than today's date.
I did it in the controller like this:

$posts = $query->where(['>', 'date_end', date('Y-m-d')])
        	->offset($pagination->offset)
        	->limit($pagination->limit)
        	->all();

Will it be correct? After all, in this case we are comparing two text values? Or is there another better way?
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2015-11-01
@R0dger

Store a DATETIME or Unix TimeStamp in the database. In your case, as I understand it, you have varChar - make an index on this field in the database, it will be faster.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question