When I do this in oracle 10g:
select to_date(trunc(SOMEINPUTdATE)) from table1
where to_date(trunc(date_column_timestamp),'MM/DD/YYYY')
>= to_date('03/11/2011' ,'MM/DD/YYYY')
I get: ORA-01843: not a valid month if I change to : 'YYYY/MM/DD', it works.
But 'MM/DD/YYYY' is a valid format right?
You're getting things mixed up a bit. TO_DATE converts a string into a DATE. If
date_column_timestampis already a date, you don't need to convert it to a date.The
ORA-01843is caused by the implicit conversion of a date to string. In other words, the following:is equivalent to (assuming the default date format
DD-MON-YYYY):So, the
TO_CHARreturns something like'11-MAR-2011', which then causesto_dateto fail because the date formats do not match.The same problem exists in your
selectclause. You don't needto_datearound atruncof a date column.