Reputation: 886
I have the following query :-
select actual_ssd
from tblsales
Is it possible to return records from tblsales
where actual_ssd
is dynamically 2 months ahead?
So, if I ran the query today, it would return all records between 01/05/2018 and 31/05/2018. And if I ran it on 04/04/2018, it would return all records between 01/06/2018 and 30/06/2018.
Upvotes: 0
Views: 34
Reputation: 146279
Sure thing
select *
from tblsales
where actual_ssd >= trunc(add_months(sysdate, 2), 'MM')
and actual_ssd < trunc(add_months(sysdate, 3), 'MM')
trunc()
on a date value performs a rounding down, depending on the format mask; with the 'MM'
argument it rounds down to the first of the current month. add_months()
does exactly what you'd think it does, add the required number of months to the date argument.
Upvotes: 3
Reputation: 49260
Use trunc
with arithmetic.
where actual_ssd >= trunc(sysdate,'mm')+interval '2' month
and actual_ssd < trunc(sysdate,'mm')+interval '3' month
Upvotes: 1