I am using oracle database. I want to execute one query to check the data between two dates.
NAME START_DATE
------------- -------------
Small Widget 15-JAN-10 04.25.32.000000 PM
Product 1 17-JAN-10 04.31.32.000000 PM
select * from <TABLENAME> where start_date
BETWEEN '15-JAN-10' AND '17-JAN-10'
But I don’t get any results from above query. I think I have to use "like" and "%". But I don’t know where to use them. Please throw some lights on this.
Judging from your output it looks like you have defined START_DATE as a timestamp. If it were a regular date Oracle would be able to handle the implicit conversion. But as it isn’t you need to explicitly cast those strings to be dates.
But we still only get one row. This is because START_DATE has a time element. If we don’t specify the time component Oracle defaults it to midnight. That is fine for the from side of the
BETWEENbut not for the until side:edit
If you cannot pass in the time component there are a couple of choices. One is to change the WHERE clause to remove the time element from the criteria:
This might have an impact on performance, because it disqualifies any b-tree index on START_DATE. You would need to build a function-based index instead.
Alternatively you could add the time element to the date in your code:
Because of these problems many people prefer to avoid the use of
betweenby checking for date boundaries like this: