Sub topic 9
Two-Digit Years: `RR` Versus `YY`
Oracle stores a DATE with a complete year, but a two-digit input does not contain enough information to identify that year by itself. The format model you give to TO_DATE determines how Oracle fills in the missing century.
This chapter assumes that you know basic SELECT syntax, Oracle DATE and VARCHAR2 values, and how to run SQL in an Oracle client.
How `YY` and `RR` Interpret a Year
YY means “use these two digits as the year within the current century.” If the current year is 2026, the current century is the 2000s:
SELECT TO_CHAR(TO_DATE('01-01-99', 'DD-MM-YY'), 'YYYY') AS yy_year
FROM dual;This returns 2099. Oracle takes the current century, 20, and appends the input 99.
RR uses a sliding rule. It considers both the two-digit input and the last two digits of the current year. This lets older applications interpret historical two-digit years more usefully.
For example, when the current year is 2026:
SELECT TO_CHAR(TO_DATE('01-01-99', 'DD-MM-RR'), 'YYYY') AS rr_year,
TO_CHAR(TO_DATE('01-01-99', 'DD-MM-YY'), 'YYYY') AS yy_year
FROM dual;The result is:
| `RR` result | `YY` result |
|---|---|
| 1999 | 2099 |
The current year affects the result, so the same SQL can produce different years in a later century.
The `RR` Decision Rule
Oracle applies this rule to the two-digit input:
| Current year ends in | Input `00`–`49` | Input `50`–`99` |
|---|---|---|
| `00`–`49` | Current century | Previous century |
| `50`–`99` | Next century | Current century |
With the current year in the range 2000–2049, RR interprets:
00through49as 2000 through 204950through99as 1950 through 1999
Therefore, in 2026, TO_DATE('01-01-26', 'DD-MM-RR') produces 2026, while TO_DATE('01-01-75', 'DD-MM-RR') produces 1975.
The exact boundary moves as time passes. That behavior was designed for applications that needed to handle dates around the transition from the twentieth to the twenty-first century.
Choosing the Safer Format
For new data, use four-digit years with YYYY. It avoids dependence on the current year and makes the input unambiguous.
SELECT TO_CHAR(
TO_DATE('01-01-2026', 'DD-MM-YYYY'),
'YYYY-MM-DD'
) AS normalized_date
FROM dual;This always means January 1, 2026, regardless of when the query runs.
Use RR only when you must process an existing two-digit-year format and you understand the century assumptions. Do not use RR to make ambiguous external data trustworthy. If a file contains 01-01-30, you still need a business rule to decide whether that means 1930, 2030, or another year.
Avoiding Display Confusion
TO_DATE returns a DATE, not a formatted string. Your SQL client may display that value using the session's NLS_DATE_FORMAT. Use TO_CHAR with YYYY when checking or exporting the result:
SELECT TO_CHAR(
TO_DATE('31-12-49', 'DD-MM-RR'),
'YYYY-MM-DD'
) AS interpreted_date
FROM dual;This makes the selected year visible and prevents the client's display settings from hiding it.
Exercise
In a session where the current year is 2026, what years do RR and YY assign to the input 15-06-75?
Show answer
RR assigns 1975 because 75 falls in the 50-99 range. YY assigns 2075 because it always uses the current century.