Skip to content
Advertisement

SQL timestamp filtering based only on time

I want to create a query in Oracle SQL that will grab records from a given time interval, during certain hours of the day, e.g. records between 10am to noon, in the past 10 days. I tried this, but it does not work:

where timestamp is of type TIMESTAMP. I have also thought of using a join, but I am struggling to find a way to filter on time of day.

Is there a way to filter using only the time, not the date, or a way to filter on time for every day in the interval?

Advertisement

Answer

If you don’t need to include exactly noon (including no fractional seconds), you could also do

As an aside, I’d hope that your actual column name isn’t timestamp. It’s legal as a column name but it is a reserved word so you’re generally much better off using a different name.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement