I am working on a PHP application that displays events. It generates a select box that allows visitors to choose a month for which events should be displayed.
My problem is in regard to the select box, which should display not only months on which an event starts or ends, but also months during which an event is still taking place (even if it started months before and ends months later).
Here is what I’ve got at the moment, it’s pretty basic and only returns months on which events start.
SELECT
DISTINCT DATE_FORMAT(start,'%M %Y') as prettydate,
DATE_FORMAT(start,'%m%Y') as monthyear
FROM
`events`
WHERE
start >= NOW()
ORDER BY
start ASC;
How can I also get February & July but also March, April, May & June 2014 in the result if the only event I’ve got in 2014 starts in February and finishes in July for example?
Thanks in advance for your help!
Assuming you don’t have any events that span more than 1 year, and using the following start/end dates:
this query:
will return:
See http://sqlfiddle.com/#!2/12b08/3 for a working example.