how to display the field date (type data = date) whose record is above it 12/29/2018

61 Views Asked by At

I have trouble in the SQL query to display the data fields whose records are above 29-12-2018 on Oracle ,

SELECT * FROM 
data 
WHERE date BETWEEN('29-12-2018' AND '01-01-2019')
ORDER BY datetime DESC
2

There are 2 best solutions below

1
Adnan Sharif On BEST ANSWER

You need to use to_date() function to convert your string to a date.

SELECT * FROM 
data 
WHERE "date" > to_date('29-12-2018','DD-MM-YYYY')
ORDER BY datetime DESC
5
Barbaros Özhan On

You can either use

SELECT *
  FROM data
 WHERE "date" > to_date('2018-12-29','yyyy-mm-dd') --> needs formatting as the second argument
 ORDER BY datetime DESC

or

SELECT *
  FROM data
 WHERE "date" > date'2018-12-29' --> literal according to "ISO 8601" standard
 ORDER BY datetime DESC

where date is converted to "date" since, it's a reserved keyword, and not possible to create a table with this column name.