Yii framework 2.0 ActiveRecord日期不在两个日期之间

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:

  1. today is NOT between from_date and to_date. And not even equal these dates (!($from_date <= $today) && !($today <= $to_date))).

OR

  1. from_date is NULL and to_date is NULL. Because in some records these dates are empty, they need to be selected and counted as well.

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')]
        ]
    ]);