mrong
asked on
add_months function in oracle
Greeting,
I try to use add_months function to get me all the data for the previous 6 month up to now.
I have select * from tbl where date>=add_months(sysdate,- 6)
The above sql will give me the data from Nov 13th to May 13th(Now).
How to get data from Nov 1st to May 13th?
Thanks.
I try to use add_months function to get me all the data for the previous 6 month up to now.
I have select * from tbl where date>=add_months(sysdate,-
The above sql will give me the data from Nov 13th to May 13th(Now).
How to get data from Nov 1st to May 13th?
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can also use this:
SELECT * FROM <<TABLE>> WHERE trunc(<<YOUR DATE COLUMN>>,'MM') >= ADD_MONTHS(SYSDATE,-6)
AND <<YOUR DATE COLUMN>> <= sysdate;
SELECT * FROM <<TABLE>> WHERE trunc(<<YOUR DATE COLUMN>>,'MM') >= ADD_MONTHS(SYSDATE,-6)
AND <<YOUR DATE COLUMN>> <= sysdate;
putting TRUNC on the column prevents use of most indexes and isn't recommended
yeah true
select * from tbl where date>='01-'||to_char(add_m onths(sysd ate,-6),'M ON-YYYY')
OR
select * from tbl where date>=LAST_DAY(add_months( sysdate,-7 ))+1
OR
select * from tbl where date>=LAST_DAY(add_months(
select * from tbl where date>=add_months(trunc(sys
both of these assume you want everything from Nov 1 of previous year up through current day and time, and that there is no future-dated data
if you might have future-dated data, then add an additional clause
AND date <= sysdate