Skip to content
Advertisement

How to compare two dates from an oracle database

I am trying to select rows from a table based on a date inside the table using the SQL query: SELECT * FROM users WHERE date1 = TO_DATE('01/01/2020', 'MM/DD/YYYY') . For some reason, this query only works for some dates but not all of them and I do not know why. When displaying the dates, the format looks like ’01/01/2020 12:00:00 AM’, but I have tried manipulating the TO_DATE() function to factor in the time and it still does not change the outcome. Any help would be greatly appreciated, if it helps, some of the dates that work are: ’01/01/2001′ and ’01/01/2000′.

Data:

Advertisement

Answer

If you want to select one day of data from a DATE column, that can contain a tiem component, use

The subtle difference to using TRUNC is that you may use index access if appropriate.

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