简体   繁体   中英

Search Between dates YII

We have a date example : 2016-05-10, i am trying to get a query from database using this date.

We have 2 tables : publish_at and 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

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

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.

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'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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