Skip to content
Advertisement

Query that will select a timeframe from specific date to today

I’m having issues in my WHERE clause selecting data from a specific day to today’s date. The day/time format in my date column is ‘7/2/2020 3:12:08 PM’.

I’ve tested a couple options but keep getting this error – ‘literal does not match format string’.

Any idea’s of how I can select all data from March 1, 2020 to current date?

Thanks!

Advertisement

Answer

In Oracle date columns are not strings, they are exactly in date datatype, so you don’t need to convert/cast it. Just use simple date literals: https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/Literals.html#GUID-8F4B3F82-8821-4071-84D6-FBBA21C05AC1

select * from table where your_date_columg >= date'2015-12-31'

or with to_date function for your string:

select * from table 
where
 your_date_columg >= to_date('2019-11-25 13:57:52',
                             'yyyy-mm-dd hh24:mi:ss')
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement