Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

2 Digit Year Reveals Inconsistent Results

kbarryAug 14 2013 — edited Aug 15 2013

As I have read what I can about implicit versus explicit dates, I have come across something I find a bit odd.  I've tried to simplify it here in this anonymous block.

declare
bad_year varchar2(30);
good_year varchar2(30);
neutral_year varchar2(30);
testdate date;
neutraldate date;


begin

testdate := to_date('01-JAN-50', 'DD-MON-YY');
--test one
bad_year := to_char(testdate, 'DD-MON-YYYY');
dbms_output.put_line(bad_year);
--test two
neutral_year := to_char(testdate, 'DD-MON-YY');
neutraldate := to_date(neutral_year);
good_year := to_char(neutraldate, 'DD-MON-YYYY');
dbms_output.put_line(good_year);

end;

The results:

01-JAN-2050

01-JAN-1950

I would think that unless you are altering your session between tests and changing the NLS_DATE_FORMAT, that the results would at least be consistent.

This has truly got me stumped.

Anyone out there understand this?

thank you,

Kristi

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 12 2013
Added on Aug 14 2013
10 comments
2,645 views