-3

How can we compare Two dates

set_up_date = 20-02-18 (in date)
expiry_date = 23-04-20 (in date)

select * 
       BETWEEN TO_NUMBER(TO_CHAR('set_up_date','YYYYMMDD')) AND 
       TO_NUMBER(TO_CHAR('expiry_date','YYYYMMDD')) 
  from dual;
jarlh
  • 42,561
  • 8
  • 45
  • 63
  • 4
    Either you need to better explain your query, or show sample data. This is not answerable right now. – Tim Biegeleisen Oct 01 '18 at 08:08
  • Did you simply miss the `select ... from ... where` -syntax? `select * from dual where to_date('20170510','YYYYMMDD') BETWEEN to_date('20170509','YYYYMMDD') and to_date('20170512','YYYYMMDD');` – Chrᴉz remembers Monica Oct 01 '18 at 08:25
  • 1
    Possible duplicate of [Check if current date is between two dates Oracle SQL](https://stackoverflow.com/questions/23398632/check-if-current-date-is-between-two-dates-oracle-sql) – Asken Oct 01 '18 at 08:26
  • 1
    `'set_up_date'` and `'expiry_date'` are string literals - they are not column names or bind variables. – MT0 Oct 01 '18 at 08:26
  • what are you expecting??? – Nikhil S Oct 01 '18 at 08:41

1 Answers1

0

'set_up_date' and 'expiry_date' are string literals - they are not column names or bind variables. You also need to use the correct syntax for a query which has statements in the order: SELECT ... FROM ... [WHERE ...] [GROUP BY ...] [ORDER BY ...].

So, if you have a table your_table with a your_date_column column of the DATE data type then you can compare it to the two DATE variables set_up_date and expiry_date identified in your question using:

SELECT * 
FROM   your_table_name
WHERE  your_date_column BETWEEN set_up_date AND expiry_date;
MT0
  • 143,790
  • 11
  • 59
  • 117