Skip to main content

Check if a Date Range Overlaps another Date Range

  • April 22, 2018
  • 0 replies
  • 1 view

Forum|alt.badge.img+2

Jim Knicely authored this tip.

The OVERLAPS Vertica built-in function evaluates two time periods and returns true when they overlap, false otherwise.

Example:

dbadmin=> SELECT (DATE '2018-04-18', DATE '2018-04-21') OVERLAPS (DATE '2018-04-16', DATE '2018-04-19');
 overlaps
----------
t
(1 row)

dbadmin=> SELECT (DATE '2018-04-18', DATE '2018-04-21') OVERLAPS (DATE '2018-04-22', DATE '2018-04-25');
 overlaps
----------
f
(1 row)

Have Fun!