Biju s
Biju s

Reputation: 430

Yii2 model search between query

I Want to impliment below mysql query in yii2 model search()

SELECT * FROM `parking_availability` WHERE  ('09:00' BETWEEN `time_start` AND `time_end` ) AND 
 ( '11:00' BETWEEN `time_start` AND `time_end` )  

I have applied like this

 $query->andFilterWhere([$this->arrivaltime,'between','time_star', 'time_end'])
->andFilterWhere([$this->departuretime,'between','time_star', 'time_end']);

But its showing error Operator '09:00' requires two operands.

Please help me , Thanks

Upvotes: 0

Views: 647

Answers (1)

gmc
gmc

Reputation: 3990

You were in the right direction in your attempts, but you got the parameters in the wrong order. The first has to be the 'between' operator:

$query->andFilterWhere(['between', $this->arrivaltime, 'time_start', 'time_end'])
->andFilterWhere(['between', $this->departuretime, 'time_start', 'time_end']);

Upvotes: 2

Related Questions