Re: Operations on "date" columns

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: Mon, 11 May 1998 13:26:43 GMT
Message-ID: <3556fc4d.3764503_at_192.86.155.100>


A copy of this was sent to Thibaut <Philippart_at_geru.ucl.ac.be> (if that email address didn't require changing) On Mon, 11 May 1998 14:32:26 +0200, you wrote:

> Hello,
>
> I would like to make some operations in a column containing dates, but I
>don't know how to do this. The aim is to add 1900 years to all record (ie.
>10/11/0098 -> 10/11/1998).
>
> Is it possible ?
> Can you help me to solve this problem ?
>
> Thank you.
> Regards,
>
> Thibaut

Here is 2 ways to do it. The first one simply adds 1900*12 months to the date field. The other one uses date conversions (convert the date to a string, convert the string into a date again)..

SQL> create table d ( d date );
Table created.

SQL> insert into d values ( to_date( '10/11/0098', 'DD/MM/YYYY' ) ); 1 row created.

SQL> select to_char( d, 'dd-mon-yyyy' ) from d; TO_CHAR(D,'



10-nov-0098

SQL> select to_char( add_months(d,1900*12), 'dd-mon-yyyy' ) from d; TO_CHAR(ADD



10-nov-1998

SQL> select to_char( to_date( to_char(d,'ddmmyy'), 'ddmmyy' ), 'dd-mon-yyyy')   2 from d;
TO_CHAR(TO_



10-nov-1998  

Thomas Kyte
tkyte_at_us.oracle.com
Oracle Government
Herndon VA  

http://govt.us.oracle.com/ -- downloadable utilities  



Opinions are mine and do not necessarily reflect those of Oracle Corporation  

Anti-Anti Spam Msg: if you want an answer emailed to you, you have to make it easy to get email to you. Any bounced email will be treated the same way i treat SPAM-- I delete it. Received on Mon May 11 1998 - 15:26:43 CEST

Original text of this message