I'm having issue while converting date format, I'm receiving as a text in the format mmddyy
( 031537 ), when I try to convert with to_date
it is returning 2037 instead 1937
Appreciate if anyone has work around and I'm using oracle version 19c
select to_date('031537','mmddyy') from dual;
03/15/2037
select to_date('031537','mmddyrr') from dual;
03/15/2037
Tried to_date
but no luck
In Oracle:
YY
date format then that always corresponds to a year in the current century;RR
date format then:
- If the specified two-digit year is
00
to49
, then
- If the last two digits of the current year are
00
to49
, then the returned year has the same first two digits as the current year.- If the last two digits of the current year are
50
to99
, then the first 2 digits of the returned year are 1 greater than the first 2 digits of the current year.- If the specified two-digit year is
50
to99
, then
- If the last two digits of the current year are
00
to49
, then the first 2 digits of the returned year are 1 less than the first 2 digits of the current year.- If the last two digits of the current year are
50
to99
, then the returned year has the same first two digits as the current year.
The conclusion is that there is no 2-digit format model which would parse 37
and give you 1937
as the year.
If you want to have a year of 1937
then pass a 4-digit year.
SELECT TO_DATE('03151937','mmddyyyy') FROM DUAL;
Alternatively, if you are always going to get a 2-digit year from the 20th century, split the string value and manually insert the century so you have a 4-digit year:
WITH data (value) AS (
SELECT '031537' FROM DUAL
)
SELECT TO_DATE(
SUBSTR(value, 1, 4) || '19' || SUBSTR(value, 5),
'MMDDYYYY'
)
FROM data
Both of which give the date: 1937-03-15 00:00:00