0

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

Biju s
  • 420
  • 1
  • 7
  • 16

1 Answers1

2

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']);
gmc
  • 3,910
  • 2
  • 31
  • 44
  • what is 'time_start', 'time_end' here and from where it is coming – Goli Dec 07 '17 at 10:28
  • I assumed they were columns in his `parking_availability ` table – gmc Dec 08 '17 at 14:28
  • will you please visit this question of mine.. https://stackoverflow.com/questions/47708512/how-to-filter-date-field-in-yii2 – Goli Dec 09 '17 at 04:31