Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date information

Status
Not open for further replies.

campbere

Technical User
Oct 10, 2000
146
0
0
US
I need to get the correct syntax for adding months to a date. I want to select the max(date) - 6 months.

I tried select (max(date) - 6MM) but that failed. The one Oracle book I have doesnt discuss this.

Thanks for your help.
 
I am pretty sure that Oracle lets you do addition and subtraction by days, so try:
Code:
SELECT (MAX(YOURDATE)) - 180
FROM my_table;

Hope that helps...


Terry M. Hoey
th3856@txmail.sbc.com

Ever notice that by the time that you realize that you ran a truncate script on the wrong instance, it is too late to stop it?
 
Oracle has an add_months function, so

add_months(max(date),-6)

should do the trick.
 
Forgot about that one Karluk.

Terry M. Hoey
th3856@txmail.sbc.com

Ever notice that by the time that you realize that you ran a truncate script on the wrong instance, it is too late to stop it?
 
It's very simple Pleas use this

Add_months(max(date),- 6 ) from .....

Manoj Bajaj
 
Hi !

This should work:
select add_months(to_date(max(YourDate)), -6) from <table_name>;

The other previous will give u error : invalid character.
To avoid this error, convert the max(yourdate) into date first and then use the add_months function.

thx,
Kavy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top