Yii2 model search between query

烂漫一生 提交于 2019-12-12 05:57:53

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/43318711/yii2-model-search-between-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!