The RR date-time format element is similar to the YY date-time format element, but it provides additional flexibility for storing cross-century date values.
With the YY date-time format element, you must specify all the digits of the year. With the RR date-time format element, you only need to specify the last two digits of the year to store the date value.
When used with the TO_DATE function, the RR date-time format element returns a value whose century depends on the specified two-digit year and the last two digits of the current year. If the YY date-time format element is used with the TO_DATE function, the returned year will always be in the same century as the current year.
If the specified two-digit year is between 00 and 49, and the last two digits of the current year are between 00 and 49, the returned year will be in the same century as the current year. If the last two digits of the current year are between 50 and 99, the returned year will be in the next century.
If the specified two-digit year is between 50 and 99, and the last two digits of the current year are between 00 and 49, the returned year will be in the previous century. If the last two digits of the current year are between 50 and 99, the returned year will be in the same century as the current year.
As shown in the following examples, the RR date-time format element returns the same value for years with different leading digits. Assume these queries are executed between 1950 and 1999:
SELECT TO_CHAR(TO_DATE('27-OCT-98', 'DD-MON-RR'), 'YYYY') "Year1" ,
TO_CHAR(TO_DATE('27-OCT-17', 'DD-MON-RR'), 'YYYY') "Year2" FROM DUAL;
The query result is as follows:
+-------+-------+
| Year1 | Year2 |
+-------+-------+
| 1998 | 2017 |
+-------+-------+
Assume these queries are executed between 2000 and 2049:
SELECT TO_CHAR(TO_DATE('27-OCT-98', 'DD-MON-RR'), 'YYYY') "Year1" ,
TO_CHAR(TO_DATE('27-OCT-17', 'DD-MON-RR'), 'YYYY') "Year2" FROM DUAL;
The query result is as follows:
+-------+-------+
| Year1 | Year2 |
+-------+-------+
| 1998 | 2017 |
+-------+-------+
From the query results of the two examples, you can see that the same value is returned regardless of whether the query is executed before or after 2000.
