Hi am using below query to retrieve records last 90 days from current date but its not working. please help me.
SELECT *
FROM adhoc_request
WHERE DATEDIFF(("d", Crdate, current_date()) < 90);
SELECT *
FROM adhoc_request
WHERE Crdate >= sysdate-90
SYSDATE includes the time portion, e.g. "04-13-2013 09:45:51"
So in effect, the query run on "04-13-2013 09:45:51" translates to
WHERE Crdate >= "2013-01-13 09:45:51"
David's suggestion works more predictably and is in most cases more correct, which first truncates SYSDATE to return just today's date before taking 90 days off it, i.e.
SELECT *
FROM adhoc_request
WHERE Crdate >= TRUNC(sysdate)-90
select *
from adhoc_request
where Crdate < DATEADD("d", -90, current_date()) < 90);
Some notes:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With