Working with Yii framework 2.0 I have a database table with the columns 'from_date' and 'to_date'. I would like to select and count all records where:
OR
I have a model which extends the ActiveRecord class, so I could use the following code to retrieve the data:
ModelClass::find()-where('big>small')->andWhere('1<2')->orWhere('3>1')->count();
I tried to read the documentation of Yii 2.0 but could not figure out how to use NOT BETWEEN OR EQUAL NULL.
For null, you can use the code below:
ModelClass::find()->where([
'from_date' => null,
'to_date' => null,
])
And from the guide, you can easily chain the where attribute: http://www.yiiframework.com/doc-2.0/yii-db-query.html#where%28%29-detail
you have pass the parameter 'NOT' before de query, example:
$query->andWhere(['not',['id'=> null]]);
You can try this
->andWhere(['NOT',
['AND',
['>=', 'fromTime', (new \DateTime($from_date))->format('H:i:s')],
['<=', 'toTime', (new \DateTime($to_date))->format('H:i:s')]
]
]);