need to extract century(20th or 21st) based on the date given
I am trying to extract a date from a string. On conversion, I am getting incorrect century for the year actual value expected value 123051 = 1951-12-30 Below is the query and result on date conversion: SELECT TO_DATE('123051','mmddyy'); 2051-12-30 Any year between 70 & 99 are auto converted to 20th century select to_date('030270','MMDDYY'); to_date ------------ 1970-03-02
0
Comments
CREATE TABLE
daniel=> copy soma from stdin;
Enter data to be copied followed by a newline.
End with a backslash and a period on a line by itself.
>> 110813
>> 123051
>> \.
daniel=> select * from soma;
dt
--------
110813
123051
(2 rows)
daniel=> \p
select dt,
decode(dt % 100 < 14, 0, 19, 20) "century",
date(decode(dt % 100 < 14, 0, 19, 20) || dt % 100 || dt // 100) "date"
from soma;
daniel=> \g
dt | century | date
--------+---------+------------
110813 | 20 | 2013-11-08
123051 | 19 | 1951-12-30
(2 rows)