M
M
Maxim2016-04-06 13:46:20
MySQL
Maxim, 2016-04-06 13:46:20

How to add condition in Where yii2?

There is a request

$news = self::find()->where(['status' => self::STATUS_ENABLE])->andWhere(['datePublished' => '2016-04-04'])->all();

How do I add a condition like datePublished < '2016-04-04' in andWhere ?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Alexey Yarkov, 2016-04-06
@KidsBout

Maybe so?

->andWhere('datePublished< :datePublished',[':datePublished' => '2016-04-04']);

M
Maxim Yakovenko, 2016-04-06
@TheLazzziest

Try the following example:

$news = self::find()
          ->where(['status' => self::STATUS_ENABLE])
          ->andWhere([ '<', 'datePublished', '2016-04-04'])->all();

M
metallix, 2016-04-06
@metallix

Maybe so?

$news = self::find()
          ->where(['status' => self::STATUS_ENABLE, 'datePublished' => '<2016-04-04'])->all();

or so -
$news = self::find()
          ->where(['status' => self::STATUS_ENABLE'])->andWhere('datePublished < :datePublished',[':datePublished' => '2016-04-04'])->all();

V
Vladimir Soldatov, 2016-04-07
@TPbIHTPABA

$news = self::find()
          ->where(['status' => self::STATUS_ENABLE])
          ->andFilterWhere([ '<', 'datePublished', '2016-04-04'])->all();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question