oracle - Issue with comparing dates in SQL -


i have table following columns

effective_start_date
effective_end_date
person_id

this on oracle db.
writing query me person active current sysdate, using following query.

select startdate, enddate, sysdate datetable sysdate between startdate , enddate; 

the issue clause never seems applied. result contains rows dont satisfy condition. suggestions on might missing.

your query looks fine, , apc suggests common pattern. means have data problem. displaying full year show why unexpected records matching, , 'bad' dates - e.g. using unexpected centuries, not unusual problem when dates manipulated using yy format mask:

select to_char(startdate, 'yyyy-mm-dd hh24:mi:ss') startdate,     to_char(enddate, 'yyyy-mm-dd hh24:mi:ss') enddate, sysdate datetable sysdate between startdate , enddate; 

in comments you've noted showed dates 4712, showed 12 using yy-mon-dd date format mask. haven't seen that, it's more common see 0012 or 1912, record enddate in 4712 ends after sysdate. it's worth verify of dates in table, not flagged where clause.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -