Tuesday, September 6, 2011

Comparing dates alphabetically

select 'april before january?' truth
from dual where
TO_CHAR(TO_DATE('10-04-2010','dd-mm-yyyy'), 'dd-mon-yyyy')
<
TO_CHAR(TO_DATE('10-01-1999', 'dd-mm-yyyy'), 'dd-mon-yyyy')

1 comment:

  1. The original was something like this:
    "SELECT col_a FROM table_1 WHERE datecol < to_char(sysdate,'DD-MON-YYYY');" For the developer this code was fine:" no syntax errors, some interesting rows returned".

    ReplyDelete