select to_char( to_date( '01/06/99' , 'mm/dd/yy' ),
'mm/dd/yyyy' ), to_char ( to_date( '01/06/1999' ,
'mm/dd/yyyy' ), 'mm/dd/yyyy' )
from dual;
The result:
TO_CHAR(TO_DATE('01/06/99','MM/DD/YY'),'MM/DD/YYYY')
-----------------------------------------------------
01/06/2099
TO_CHAR(TO_DATE('01/06/99','MM/DD/YYYY'),'MM/DD/YYYY')
-----------------------------------------------------
01/06/1999
Well, the obvious fix is to change to the four-digit date
format, but that is not the extent of my problem. I know
the reason this is happening is because according to the
Oracle book ÿffffc3ÿffffa2ÿffffe2ÿffff82ÿffffacÿffffc5ÿffff9350-99 use the current century (so 99 becomes
1999) while year values of 00-49 are rounded to the next
century (so 01 becomes 2001). This was obviously written
in 1999 - so now that the current century is 2000, 99
becomes 2099. But the big problem that I was having is
when dates are passed as parameters. For some reason,
Oracle is still only accepting the two-digit year when
passed as a parameter and then the above error applies.
What we have had to do so far is to change the date to a
string using to_date, pass it as parameter, do what ever
changes to that variable, and change it back to a date
value. There has to be an easier way. Any suggestions?
* Sent from AltaVista http://www.altavista.com Where you can also find related Web Pages, Images, Audios, Videos, News, and Shopping. Smart is Beautiful
I.E.
TO_CHAR(TO_DATE('01/06/99','MM/DD/YY'),'MM/DD/YYYY')
-----------------------------------------------------
01/06/2099
TO_CHAR(TO_DATE('01/06/99','MM/DD/RR'),'MM/DD/YYYY')
-----------------------------------------------------
01/06/1999
HTH
James
In article <26f4216e...@usw-ex0110-075.remarq.com>,
Sent via Deja.com http://www.deja.com/
Before you buy.
James Lorenzen wrote:
> [good stuf snipped]
Just a little warning: remember that the RR format is fine for "recent"
dates,
but if you have anyone born before 1950 (data for insurance policies etc)
then the RR format will give you grief when it interprets "49" as "2049".
Mungo
--
Mungo Henning - it's a daft name but it goes with the face...
mungoh@itacs.strath.ac.uk.http://www.itacs.strath.ac.uk/
I speak for me, not my employer.
to_date('01-JAN-1999','DD-MON-YYYY')
and
to_char(sysdate,'DD-MON-YYYY')
Mungo Henning <mun...@itacs.strath.ac.uk> wrote in message
news:387DE3D7...@itacs.strath.ac.uk...
If you cast "to_date" a date variable (don't ask me why you would
like to do that), then no matter how much care you took in placing
the correct date in the variable, the result will be a date after 2000.
For example
a_date DATE;
a_date := to_date('12/10/1998','DD/MM/YYYY');
a_date := to_date(a_date);
now a_date has a 12/10/2098 value!
Steve McDaniels <steve.m...@sierra.com> wrote in message
news:85lnet$lki$1...@plo.sierra.com...
SQL> DECLARE
2 a_date DATE;
3 BEGIN
4 a_date := to_date('12/10/1998','DD/MM/YYYY');
5 DBMS_OUTPUT.PUT_LINE(to_char(a_date,'DD/MM/YYYY'));
6 a_date := to_date(a_date);
7 DBMS_OUTPUT.PUT_LINE(to_char(a_date,'DD/MM/YYYY'));
8 a_date := to_date('12/10/1998','DD/MM/YYYY');
9 a_date := to_date(a_date,'DD/MM/YYYY');
10 DBMS_OUTPUT.PUT_LINE(to_char(a_date,'DD/MM/YYYY'));
11 END;
12 /
12/10/1998
12/10/2098
12/10/0098
PL/SQL procedure successfully completed.
Now where in heck did that 0098 come from? Proving once again you have
to be VERY careful what you ask for when it comes to date I/O in Oracle.
Hope this gives you a chuckle,
Paul
In article <85qgh1$2nf2$1...@ulysses.noc.ntua.gr>,
If you need to do a to_date to, for example, guarantee the correct century
according to the 'RR' rules, when you aren't too confident how the date has
been handled you can do something like
to_date(to_char(:my_date),'dd-Mon-rr').
No.
It because that the datatype of the 1st parameter of TO_DATE() function
is CHAR/VARCHAR2!
If you put a DATE in the 1st parameter, Oracle will implicitly convert
to a string using TO_CHAR() function.
pber...@my-deja.com a écrit :
> Sofia,
> And if you want to see something even more bizarre, look at what
> happened when I tried to prevent the century shift by specifying a
> format mask when TO_DATEing the date:
>
> SQL> DECLARE
> 2 a_date DATE;
> 3 BEGIN
> 4 a_date := to_date('12/10/1998','DD/MM/YYYY');
> 5 DBMS_OUTPUT.PUT_LINE(to_char(a_date,'DD/MM/YYYY'));
> 6 a_date := to_date(a_date);
> 7 DBMS_OUTPUT.PUT_LINE(to_char(a_date,'DD/MM/YYYY'));
> 8 a_date := to_date('12/10/1998','DD/MM/YYYY');
> 9 a_date := to_date(a_date,'DD/MM/YYYY');
> 10 DBMS_OUTPUT.PUT_LINE(to_char(a_date,'DD/MM/YYYY'));
> 11 END;
> 12 /
> 12/10/1998
> 12/10/2098
> 12/10/0098
>
> PL/SQL procedure successfully completed.
>
> Now where in heck did that 0098 come from? Proving once again you have
> to be VERY careful what you ask for when it comes to date I/O in Oracle.
> Hope this gives you a chuckle,
> Paul
>
I presume your default format is 'DD/MM/YY', so
- lines 4 and 5 : OK
- lines 6 and 7 : automatic conversion of the date into char using the
default format
gives '12/10/98' (using the current century for the
output)
- lines 9 and 10 : first automatic conversion like above, and conversion to
a date using the
given format, so the '98' corresponds to 'YYYY' !
Funny !
Pierre
The real message here is that in Oracle systems you can never go
wrong if you always pass a date as AND accept a date from, a character
string with a 4 digit year and use the same character string
consistently:
param1 := TO_CHAR(SYSDATE,'MMDDYYYYHH24MISS');
new_date := TO_DATE(param1,'MMDDYYYYHH24MISS');
Any method that relies on factors outside the programmers direct and
continual control, such as NLS_DATE_FORMAT, is subject to failure.
I'll get down off my soapbox now.
Have a nice day,
Paul
select * from v$nls_parameters
where parameter = 'NLS_DATE_FORMAT'
yields:
NLS_DATE_FORMAT DD.MM.RR
The dbms-Output of the block
declare
wDate date ;
begin
wDate := to_date('31.12.1949','DD.MM.YYYY') ;
dbms_output.put_line('Before: ' || to_char(wDate,'DD.MM.YYYY')) ;
wDate := to_date(wDate) ;
dbms_output.put_line('After: ' || to_char(wDate,'DD.MM.YYYY')) ;
wDate := to_date('1.1.1950','DD.MM.YYYY') ;
dbms_output.put_line('Before: ' || to_char(wDate,'DD.MM.YYYY')) ;
wDate := to_date(wDate) ;
dbms_output.put_line('After: ' || to_char(wDate,'DD.MM.YYYY')) ;
wDate := to_date('31.12.2049','DD.MM.YYYY') ;
dbms_output.put_line('Before: ' || to_char(wDate,'DD.MM.YYYY')) ;
wDate := to_date(wDate) ;
dbms_output.put_line('After: ' || to_char(wDate,'DD.MM.YYYY')) ;
wDate := to_date('1.1.2050','DD.MM.YYYY') ;
dbms_output.put_line('Before: ' || to_char(wDate,'DD.MM.YYYY')) ;
wDate := to_date(wDate) ;
dbms_output.put_line('After: ' || to_char(wDate,'DD.MM.YYYY')) ;
end ;
is as follows:
Before: 31.12.1949
After: 31.12.2049
Before: 01.01.1950
After: 01.01.1950
Before: 31.12.2049
After: 31.12.2049
Before: 01.01.2050
After: 01.01.1950
In article <85qgh1$2nf2$1...@ulysses.noc.ntua.gr>,
"Sofia" <so...@eexi.gr> wrote:
> interesting fact:
>
> If you cast "to_date" a date variable (don't ask me why you would
> like to do that), then no matter how much care you took in placing
> the correct date in the variable, the result will be a date after
2000.
>
> For example
>
> a_date DATE;
>
> a_date := to_date('12/10/1998','DD/MM/YYYY');
> a_date := to_date(a_date);
>
> now a_date has a 12/10/2098 value!
>