Answer the question
In order to leave comments, you need to log in
How to find the intersection of two date ranges?
There are two date ranges: 01.01.2019 - 31.05.2019
and 01.03.2019 - 31.12.2019
.
How to find their intersection?
As a result, you need to get 01.03.2019 - 31.05.2019
:
Answer the question
In order to leave comments, you need to log in
Intersection condition:
start1 < end2 && start2 < end1 Intersection
area:
[max(start1, start2), min(end1, end2)]
Postgres knows how to work with date ranges.
set datestyle to DMY;
select daterange('01-01-2019'::date,'31-05-2019'::date) * daterange('01-03-2019'::date,'31-12-2019'::date)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question