Why between date is not return data for this query?

Hello
I have a table with this structure and I write this query to retrieve a few lines based on certain conditions, but this query returns no data. Can you please tell why?
ID     DT

003     11/8/2011
002     10/8/2011
001     9/8/2011
And the execution of the query:
SELECT * FROM TABLE_NAME WHERE DT BETWEEN TO_DATE('08/08/2011','dd/mm/yyyy') AND TO_DATE('12/08/2011','dd/mm/yyyy');
Published by: starting August 13, 2011 07:10

>

>

But what is the problem with that, why this date does not match when I'm providing the date format?

What part don't you understand? You have not used TO_DATE when inserting data and default date format is dd/mm/yyyy, right? Same default date format is used if you are running:

SELECT * FROM TABLE_NAME

Original of your post States select returns above:

ID     DT

003     11/8/2011
002     10/8/2011
001     9/8/2011

So the dates that you inserted are November 8, 2011, October 8, 2011-September 8, 2011. TO_DATE('08/08/2011','dd/mm/yyyy') is now August 8, 2011 and TO_DATE('12/08/2011','dd/mm/yyyy') is August 12, 2011. Then of course:

SELECT * FROM TABLE_NAME WHERE DT BETWEEN TO_DATE('08/08/2011','dd/mm/yyyy') AND TO_DATE('12/08/2011','dd/mm/yyyy').

will return all the lines. Bottome line - never write code that uses the implicit conversions date since your code becomes dependent on the NLS client settings and maybe working for a client and fail or produce erroneous results for other customers.

SY.

Tags: Database

Similar Questions

Maybe you are looking for