简体   繁体   English

在日期YII之间搜索

[英]Search Between dates YII

We have a date example : 2016-05-10, i am trying to get a query from database using this date. 我们有一个日期示例:2016-05-10,我正在尝试使用此日期从数据库中获取查询。

We have 2 tables : publish_at and end_at 我们有2个表:publish_at和end_at

SELECT * FROM  `news` WHERE end_at <=  '2016-05-11' AND publish_at >=  '2016-05-10'

This returns incorrect data as it does not show an event that has publish_at :2016-05-10 and end_at 2016-05-12 这会返回不正确的数据,因为它不会显示具有publish_at:2016-05-10和end_at 2016-05-12的事件

SELECT * FROM news WHERE '2016-05-11' BETWEEN publish_at AND end_at

This returns correct item but does not return if date is 10 or 12 only if between 这将返回正确的项目,但如果日期为10或12,则仅在两者之间不返回

The first query return correct data since the query reqest all events that publish in the 2016/05/10 or after and ended in the 2016/05/11 or before. 第一个查询返回正确的数据,因为查询需要在2016/05/10或2016/05/11之前或之后发布的所有事件。

Change the query to 将查询更改为

Select * from news where end_at between '2016-05-10' and '2016-05-11' or publish_at betweeb '2016-05-10' and '2016-05-12'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM