compare two dates in oracle
(I am using Oracle10g & Java(JDBC & Servlets))
Following is my query to compare ETIME with sysdate.
If ETIME+7days is greater than sysdate then I want to select Y and if
ETIME+7days is less than sysdate I want to select N.
select USER,
CASE WHEN to_date(ETIME+7, 'YYYY-MON-DD HH24:MI:SS') >=
to_date(sysdate, 'YYYY-MON-DD HH24:MI:SS')
THEN 'Y' ELSE 'N' END THE_TIME
from TABLE_NAME
where THE_KEY='123456789'
[Note: In database value of ETIME for THE_KEY is 27/09/2013]
Above query returns N today. Few days back it was returning Y. So I think
I am doing comparison of two dates wrong way.
Any suggestion will be appreciated.
No comments:
Post a Comment