I have a row with a date range
title | fromDate | tillDate
------------------------------------
my event | 2014-03-12 | 2014-03-13
my event 2 | 2014-03-14 | 2014-03-17
my event 3 | 2014-03-01 | 2014-03-10
my event 4 | 2014-03-01 | 2014-03-09
Now I have a second pair of date range and I want to check if the event is in the date range .. for example
checkStartDate = 2014-03-10 checkEndStartDate = 2014-03-14
So in the range would be "my event" , "my event 2" and "my event 3" ...
At this moment I want to just try and get ALL the dates between my range (so between 2014-03-10 and 2014-03-14) and write one big query for it ... But there must be an easier way to do this right?
SELECT title FROM table WHERE (DATE('2014-03-10') BETWEEN DATE(fromDate) AND DATE(tillDate) OR DATE('2014-03-14') BETWEEN DATE(fromDate) AND DATE(tillDate) OR (DATE('2014-03-10') <= DATE(fromDate) AND DATE('2014-03-14') >= DATE(tillDate)))
Try this:
select title from table
where checkStartDate <= fromDate
and checkEndStartDate <= tillDate
I have edited my answer.
使用此代码
select * from events_table where fromDate >= checkStartDate and tillDate <= checkEndStartDate
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.