create table foo ( id integer not null primary key, planned_start date, planned_end date, actual_start date, actual_end date ); insert into foo (id, planned_start, planned_end, actual_start, actual_end) values (1, date '2014-01-01', date '2014-08-01', date '2014-01-02', date '2014-07-30'), (2, date '2014-01-01', date '2014-08-01', date '2014-09-01', date '2014-09-24') ;
Querying the above table using:
select * from foo where (planned_start, planned_end) overlaps (actual_start, actual_end);
returns:
id | planned_start | planned_end | actual_start | actual_end ---+---------------+-------------+--------------+----------- 1 | 2014-01-01 | 2014-08-01 | 2014-01-02 | 2014-07-30