Kkunnuthara
Kkunnuthara

Reputation: 69

Oracle SQL check whether a date is between today's date and another date

Is there a way by which I can simplify the below using BETWEEN ?

select  * 
from support 
where 
(datereceived <= sysdate) and (datereceived >= add_months (sysdate,-3));

Many thanks

Upvotes: 0

Views: 34

Answers (2)

Gordon Linoff
Gordon Linoff

Reputation: 1269603

Given that datereceived probably refers only to something that has already happened, I don't think you need to check that there is no future date.

So, a simpler comparison would be:

where datereceived >= add_months(sysdate, -3)

Then, you might not realize that sysdate has a time component. And you probably don't care about specific times. So, you might actually intend:

where datereceived >= add_months(trunc(sysdate), -3)

Upvotes: 1

Ankit Bajpai
Ankit Bajpai

Reputation: 13509

You can write -

SELECT *
  FROM support
 WHERE datereceived BETWEEN ADD_MONTHS(SYSDATE, -3) AND SYSDATE;

Upvotes: 1

Related Questions