user1658567 user1658567 - 7 months ago 9
SQL Question

How to retrieve the records based on a date from oracle database

I have a table with date column in it. I need to fetch the records from it based on
the given date.

Currently when i used the query:

select * from workingemployee_data where created_date like '20-Jan-2012'


I am getting those records which have created_date on 20-Jan-2012

But i want to get the records those were created 10 days earlier to a given
date (i.e) 20-Jan-2012.

Please suggest me on this.

mvp mvp
Answer

This gives all records between today and 10 days ago:

SELECT *
FROM workingemployee
WHERE created_date BETWEEN sysdate - INTERVAL '10' DAY
                       AND sysdate

This gives all records entered exactly 10 days ago:

SELECT *
FROM workingemployee
WHERE created_date = sysdate - INTERVAL '10' DAY

Replace sysdate with exact date if you want.