Home > Back-end >  Oracle results from last X days while ignoring time
Oracle results from last X days while ignoring time

Time:10-01

Right now I have the following query which returns results from the last 60 days

select * from my_table where date_col > sysdate - 60

But it is also taking time of the day into consideration. For example today is

Sept 30 2021 10:30:00 AM

and the query would return results from Oct 01 2021 10:31:00 AM, but not from Oct 01 2021 10:29:00 AM

How can I modify the query that it does not care about the time when getting the last 60 days? I would the query to return results even if the row had a date of Oct 01 2021 00:00:01 AM

CodePudding user response:

It sounds like you just want to trunc the sysdate. I'd guess that you want to do a >= as well.

WHERE date_col >= trunc(sysdate) - 60
  • Related