Re: Question: Update Year for a Date Field

From: Ken Denny <kedenny_at_mail.concentric.net>
Date: 1996/01/05
Message-ID: <4ci3cb$pbc_at_spectator.cris.com>#1/1


How about:

   update <table> set <date_field>=

      to_date(to_char(to_number(to_char(<date_field>,'YYMMDD'))+10000)
      ,'YYMMDD') where <condition>;

I couldn't read all your original post so I didn't know if you wanted to add a year or subtract a year. This will add a year, to subtract a year simply change the + to a -. There is one drawback. In your example, the current year is 95 so it will work OK. If the original year was a leap year and the month and day were Feb 29, you would have a problem because Feb 29 of the year before or the year after would not be a valid date.

Mai wrote:
>
> Does anyone know the SQL statements/functions to update Year for a DATE field in a table on Oracle???? i,e, update the value of a =
 field from dd-MMM-95 to dd-MM
> Without changing the values of Month and Day...
>
> If you have an answer Please post or email me at mai_at_mcs.com.
>
> Thanks a lot!!
>

Ken Denny
Insight Industries, Inc.
RTP, NC
All opinions are my own, Received on Fri Jan 05 1996 - 00:00:00 CET

Original text of this message