|
Re: How to select values between today minus 3 months ant today minus 2 months [message #372431 is a reply to message #372428] |
Tue, 13 February 2001 03:10 |
Balazs VISSY
Messages: 17 Registered: January 2001
|
Junior Member |
|
|
The ADD_MONTH function does the trick. For examle, the condition should look like
where datefield between ADD_MONTH(SYSDATE,-3) and ADD_MONTH(SYSDATE,-2)
It gives true value for today (02-13) when the datefield is higher than 2000-11-13 and no more than 2000-12-13.
The only trick you have to be careful with is that it counts EXACTLY 3 and 2 month down the current date, that is:
1. The items on 11-13, but with an earlier hour than the current time won't be returned by the select. (Solve the problem by reseting the SYSDATE by the TRUNC function:
where datefield between ADD_MONTH(TRUNC(SYSDATE),-3) and ADD_MONTH(TRUNC(SYSDATE),-2);
2. If you are intrested in the complete month (eg. november) truncate the SYSDATE to 1th of the month: TRUNC(SYSDATE,'mm');
I hope these help,
Balage
|
|
|