Your query looks fine, and as APC suggests this is a common pattern. Which means you have a data problem. Displaying the full year will show why the unexpected records are matching, and any 'bad' dates - e.g. using unexpected centuries, which is not an unusual problem when dates are manipulated using a YY
format mask:
select to_char(startDate, 'YYYY-MM-DD HH24:MI:SS') as startDate,
to_char(endDate, 'YYYY-MM-DD HH24:MI:SS') as endDate, sysdate
from dateTable
where sysdate between startDate and endDate;
In the comments you've already noted that this showed dates from 4712
, which showed as just 12
using your YY-MON-DD
date format mask. I haven't seen exactly that, it's more common to see 0012
or 1912
, but a record with endDate
in 4712
certainly ends after sysdate
. It's probably worth verify all of the dates in the table, not just those that were flagged by that where
clause.