Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> add_months problem...

add_months problem...

From: Duncan Hodson <duncan_at_tronze.demon.co.uk>
Date: Tue, 5 Jan 1999 13:29:14 -0000
Message-ID: <915542833.3246.0.nnrp-08.c2debfb5@news.demon.co.uk>


Hi all you Oracle gurus,

I have a problem with the add_months command. The command to demonstrate the problem is...

select add_months('28-FEB-96', 1) from dual;

If i add a month to '28-FEB-96' i get '28-MAR-96'. Fine because 1996 is a leap year.
If i add a month to '29-FEB-96' i get '31-MAR-96'. Not good. I want '29-MAR-96'.
If i add a month to '27-FEB-96' i get '27-MAR-96'. Fine. If i add a month to '28-FEB-97' i get '31-MAR-97'. Not good. I want '28-MAR-97'. Oracle's being too clever (again!) and is detecting that the 28th/29th February is the last day in that month so is giving me the last day of the next month.

I want it to give me either the same day number in the next month, or if we're at '31-JAN-98' i want it to return '28-FEB-98' (the closest date to 31 in the next month).

Is there a way to return the date's i'm expecting, or am i gonna have to do some nasty date-to-string-then-fiddle-with-it processing to return the desired results? I'd rather not because i use add_months to calculate due dates on a monthly/quarterly/biannually basis and it's all contained in a neat single update statement.

Cheers muchly in advance.

Received on Tue Jan 05 1999 - 07:29:14 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US