The RR datetime format element is similar to the YY datetime format element, but the RR datetime format element provides additional flexibility for storing date values across centuries.
In the YY datetime format element, you need to specify all the digits of the year. However, in the RR datetime format element, you can store date values by specifying only the last two digits of the year.
If you use the RR datetime format element with the TO_DATE function, the century of the return value varies based on the specified two-digit year and the last two digits of the current year. If you use the YY datetime format element with the TO_DATE function, the year returned always has the same century as the current year.
If the specified two-digit year is 00 to 49 and the last two digits of the current year are 00 to 49, the returned year has the same century as the current year. If the last two digits of the current year are 50 to 99, the first two digits of the returned year are the present century plus 1.
If the specified two-digit year is 50 to 99 and the last two digits of the current year are 00 to 49, the first two digits of the returned year are the present century minus 1. If the last two digits of the current year are 50 to 99, the returned year has the same century as the current year.
As shown in the following example, the RR datetime format element returns the same values from years whose first two digits are different. Assume that the following query is run 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 that the following query is run 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 |
+-------+-------+
As shown in the preceding two examples, the query returns the same values regardless of whether it is executed before or after the year 2000.