CC Date format code defaults to current centry

Started by Joe Brownabout 21 years ago5 messagesbugs
Jump to latest
#1Joe Brown
joebrown@rclooke.com

joe=> select to_date('19450323','CCYYMMDD');
to_date
------------
2045-03-23
(1 row)

joe=> select to_date('19450323','YYYYMMDD');
to_date
------------
1945-03-23
(1 row)

I thought the former would be "more" correct. But it seems I am mistaken.

#2Bruce Momjian
bruce@momjian.us
In reply to: Joe Brown (#1)
Re: CC Date format code defaults to current centry

Joe Brown wrote:

joe=> select to_date('19450323','CCYYMMDD');
to_date
------------
2045-03-23
(1 row)

joe=> select to_date('19450323','YYYYMMDD');
to_date
------------
1945-03-23
(1 row)

I thought the former would be "more" correct. But it seems I am mistaken.

Uh, 1945 _is_ in the 20th century, but I can see how it is confusing.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
#3Andre Maasikas
andre@abs.ee
In reply to: Bruce Momjian (#2)
Re: CC Date format code defaults to current centry

Bruce Momjian wrote:

Joe Brown wrote:

joe=> select to_date('19450323','CCYYMMDD');
to_date
------------
2045-03-23
(1 row)

joe=> select to_date('19450323','YYYYMMDD');
to_date
------------
1945-03-23
(1 row)

I thought the former would be "more" correct. But it seems I am mistaken.

Uh, 1945 _is_ in the 20th century, but I can see how it is confusing.

Yes, but the other way around: to_date('19450323','CCYYMMDD')
shoold be a year in the 19th century?

ps another db seems to disallow CC on input - maybe because one can
get into weird situations like to_date('2005 18','YYYY CC') or something
similar.

Andre

#4Karel Zak
zakkr@zf.jcu.cz
In reply to: Bruce Momjian (#2)
Re: [BUGS] CC Date format code defaults to current centry

On Sun, 2005-03-13 at 21:24 -0500, Bruce Momjian wrote:

Joe Brown wrote:

joe=> select to_date('19450323','CCYYMMDD');
to_date
------------
2045-03-23
(1 row)

joe=> select to_date('19450323','YYYYMMDD');
to_date
------------
1945-03-23
(1 row)

I thought the former would be "more" correct. But it seems I am mistaken.

Uh, 1945 _is_ in the 20th century, but I can see how it is confusing.

It ignored CC value if there was YY (YYYY, ..). And YY=45 is 2045:

/*
* 2-digit year
*/
if (tmfc->year < 70)
tmfc->year += 2000;
else
tmfc->year += 1900;

I think it's very special case when you define YY and CC and code
should detects it and counts year as (CC-1)*100+YY. The right answers:

CC+YY

test=# select to_date('20450112', 'CCYYDDMM');
to_date
------------
1945-12-01

CC+Y

test=# select to_date('2090112', 'CCYDDMM');
to_date
------------
1909-12-01

For YYY/YYYY it ignore CC option.

The patch (with docs changes) is in the attachment.

Karel

--
Karel Zak <zakkr@zf.jcu.cz>

Attachments:

formatting-17032005.patch.gzapplication/x-gzip; name=formatting-17032005.patch.gzDownload
#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: Karel Zak (#4)
Re: [BUGS] CC Date format code defaults to current centry

Karel Zak <zakkr@zf.jcu.cz> writes:

I think it's very special case when you define YY and CC and code
should detects it and counts year as (CC-1)*100+YY. The right answers:
...
The patch (with docs changes) is in the attachment.

Applied to HEAD and 8.0.

regards, tom lane