Reputation: 443
I have events listed in my MySQL database.
Events have a start_date (date) and end_date (date) fields.
In my application users can click on a specific day using a calendar. So, if they click today they are taken to /events?day=2013-08-08 and all events from that day are shown on the page.
This was working great until I started adding multi day events. Since previously I was just asking MySQL for all events where start_date == the user chose date, I only get events that START on that day, BUT I also want events that may have started before that day but are still going ON that day.
How can I query items like this? All events that either start on this day, or started earlier but havent yet ended by this day.
Upvotes: 0
Views: 211
Reputation: 2495
If your end date is not yet set for the tasks still going on:
where '2013-08-08' == start_date or end_date is null
Upvotes: 0
Reputation: 3288
where start_date>='$inputdate' AND end_date<='$inputdate'
Should do it
Upvotes: 0
Reputation: 360572
SELECT ...
FROM yourtable
WHERE '2013-08-08' BETWEEN start_end AND end_date
where
foo BETWEEN bar AND baz
is the SQL equivalent of
(bar <= foo) AND (foo <= baz)
Upvotes: 8