-1
Task Table
id  name    start_date  expiry_date
1   Task 1  09-05-2016  11-05-2016
2   Task 2  10-05-2016  13-05-2016
3   Task 3  11-05-2016  12-05-2016 
4   Task 4  17-05-2016  20-05-2016
5   Task 5  18-05-2016  26-05-2016

I need to find all the task from a given date range where each date from range falls between start_date and expiry_date. suppose input is 10-05-2016 to 12-05-2016.

id  name    start_date  expiry_date
1   Task 1  09-05-2016  11-05-2016
2   Task 2  10-05-2016  13-05-2016
3   Task 3  11-05-2016  12-05-2016 
snieguu
  • 2,073
  • 2
  • 20
  • 39
Ankit Tater
  • 599
  • 3
  • 9
  • 26

2 Answers2

1

You can use this condition to check if two date ranges overlap:

WHERE 
    StartA <= EndB 
    AND EndA >= StartB

Your query should be:

SELECT *
FROM tbl
WHERE
    start_date <= '12-05-2016'
    AND expiry_date >= '10-05-2016'
Community
  • 1
  • 1
Felix Pamittan
  • 31,544
  • 7
  • 41
  • 67
0

Hoping that start_date is always less than expiry_date

SELECT * FROM Task WHERE start_date <= '12-05-2016' AND expiry_date >= '10-05-2016'
Naruto
  • 4,221
  • 1
  • 21
  • 32