Query to see that the start_date and end_date records fall between the date range

I have a holiday record that has start_date and end_date

I want to execute a query where I have the date "2015-05-05" and "2015-06-05". I want to see what holiday records fall between these dates and can overlap, for example one holiday record can have start_date from '2015-06-01' and end_date from '2015-07-10'. I would like this to be found in the query

How would you write a query for this?

+3


source to share


3 answers


Try something like this:

select * from tablename
where (start_date, end_date) OVERLAPS ('2015-05-05', '2015-06-05')

      



You can find information OVERLAPS

on this page: http://www.postgresql.org/docs/current/static/functions-datetime.html

+2


source


Try this query



select * from tablename
where start_date between '2015-05-05' and '2015-06-05' and end_date between '2015-05-05' and '2015-06-05'

      

0


source


try it

select * from tablename
where  
'2015-05-05' between start_date and end_date or
'2015-06-05' between start_date and end_date or
(start_date<='2015-05-05'  and end_date>='2015-06-05')

      

0


source







All Articles