0

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.

Jay
  • 443
  • 8
  • 23
  • As long as the type of field is DATE, you can compare them using < > and DATE_SUB http://stackoverflow.com/questions/13448340/sql-greater-than-date – user1020317 Aug 08 '13 at 15:23

3 Answers3

8
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)
Marc B
  • 356,200
  • 43
  • 426
  • 500
0
where start_date>='$inputdate' AND end_date<='$inputdate'

Should do it

Dave
  • 3,280
  • 2
  • 22
  • 40
0

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

Travis Hegner
  • 2,465
  • 1
  • 12
  • 11