tags:

views:

134

answers:

2

updated_date = 08-Jun-2010;

I have a query like this

select * from asd whre updated_date <= todate('08-Jun-2010', 'dd-MM-yy');

but i am not getting any result. it is wotking only if todate is 09-Jun-2010...

ie my equalto operator is not working properly.

y is it like that ny help?

+7  A: 

In Oracle a DATE is a point in time. It always has a time component with a precision to the second. todate('08-Jun-2010', 'dd-Mon-yyyy') is in Oracle the same as todate('08-Jun-2010 00:00:00', 'dd-Mon-yyyy hh24:mi:ss'). So if you select rows up to that date you won't get any row on that day with a time component not equal to 00:00.

If you want to select all the rows up to and including 08-JUN-2010, I would suggest using:

< to_date('09-06-2010', 'dd-MM-yyyy')

or

<= to_date('08-06-2010 23:59:59', 'dd-MM-yyyy hh24:mi:ss')

Note - I corrected your date format: you need to use MON if you want to use the abbreviated month name. I would suggest using MM instead, so that you won't get error when someone changes its client settings (NLS_DATE_LANGUAGE). Also prefer the use of YYYY instead of YY.

Vincent Malgrat
I think Abbreviated name of month format is 'MON' not 'MMM'
Sujee
+1 for the reason for using 'MM' instead of "Abbreviated name of month" format.
Sujee
@Sujee: thanks I've updated my answer
Vincent Malgrat
+2  A: 

Check this,

select to_date('08-Jun-2010', 'dd-MON-yyyy') from dual;

It is equal to 2010-06-08 00:00:00. Notice the time.

The updated_date has time portion. To include them, please use this query,

select * from asd where trunc(updated_date) <= to_date('08-Jun-2010', 'dd-MON-yyyy');

The default TRUNC function for date parameter will remove the time.

Refer Trunc

Sujee