0

I have a small problem with selecting some results from the database. The results I'm trying to select have a start_date and end_date which store the full date. My client wants a feature on his site to filter all of the records by month.

Here are a couple of example records:

id  start_date  end_date
01  01.03.13    20.05.13
02  12.04.13    30.06.13
03  24.05.13    29.07.13
04  10.05.13    30.05.13  
05  19.06.13    13.08.13
06  03.07.13    18.09.13

If the month is 05, then records id 01-04 should be displayed.

Any ideas how this would be done with MySQL?

4
  • Are you filtering by start_date? end_date? both? Commented May 4, 2013 at 0:44
  • At this moment I'm not filtering anything - I'm trying to figure out how to get those records. I was thinking of using start_date >= MONTH AND end_date <= MONTH but that won't work in this case. Commented May 4, 2013 at 0:45
  • Are you really storing the dates as strings, instead of DATE type? Commented May 4, 2013 at 0:46
  • No, I'm storing them as DATE type :) Commented May 4, 2013 at 0:46

2 Answers 2

3

This query will return all events whose range includes May 2013.

SELECT *
FROM MyTable
WHERE start_date < '2013-06-01'
AND end_date >= '2013-05-01'
Sign up to request clarification or add additional context in comments.

Comments

0

try

select id from yourTable where month(start_date) == 5 or month(end_date)==5

1 Comment

This won't find row 02. It starts in April and ends in June.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.