-5

I have the following columns:

  • date_start | date_end
  • 2013-01-14 | 2013-01-16
  • 2013-01-16 | 2013-03-18
  • 2013-01-22 | 2013-03-21
  • 2013-02-02 | 2013-02-10
  • 2013-03-25 | 2013-03-28

i need to create a sql statment that I can filter these record with

date_start: 2013-01-17 date_end:2013-03-22

and the found results to be:

  • date_start | date_end
  • 2013-01-16 | 2013-03-18
  • 2013-01-22 | 2013-03-21
  • 2013-02-02 | 2013-02-10

does anyone know how to do this?

thank you

user2062455
  • 411
  • 5
  • 14
  • This is an issue of determining if date ranges overlap. See [this answer][1] [1]: http://stackoverflow.com/questions/325933/determine-whether-two-date-ranges-overlap/325964#325964 – Charles Bretana Apr 10 '13 at 16:58

3 Answers3

0

try this

 select * from your_table where date_start >=  '2013-01-17'
                          and   date_end   <=  '2013-03-22'
echo_Me
  • 37,078
  • 5
  • 58
  • 78
0
SELECT *
FROM table
WHERE date_start BETWEEN '2013-01-17' AND '2013-03-22'
  AND date_end BETWEEN '2013-01-17' AND '2013-03-22'
Sammitch
  • 30,782
  • 7
  • 50
  • 77
0
SELECT * FROM `table` WHERE `date_start` > '2013-01-17' && `date_end` < '2013-03-22'

You will need to replace table with your actual table name in your database.

OdinX
  • 4,135
  • 1
  • 24
  • 33