Oracle 23.26Data typesLab-verified · 2026-11-28

ORA-01810: format code appears twice

The same kind of format element appears twice in the mask — most often MM (month) typed where MI (minutes) was meant.

Oracle AI Database 26ai Free 23.26.3.0.0
ORA-01810: format code appears twice

Jump to a cause

  1. 01MM (month) used for minutes instead of MI
  2. 02Both AM and PM written in one mask
  3. 03MM written twice in NLS_DATE_FORMAT

Lab-verifiedReproduced and fixed on Oracle AI Database 26ai Free 23.26.3.0.0 · 2026-11-28 · container image gvenzl/oracle-free:23-slim

ORA-01810 means the date format mask contains two elements for the same thing. In Oracle, MM is the month and MI is the minutes, so HH24:MM:SS asks for the month twice. AM and PM are also the same element (the meridian indicator), so a mask can only have one of them.

All three common cases were reproduced and fixed below.

01MM (month) used for minutes instead of MI

TO_DATE(raw_time, 'YYYY-MM-DD HH24:MM:SS') failed with ORA-01810 because MM appears twice.

Be careful with TO_CHAR: the same mistake gives no error there. For 10:30:15, HH24:MM:SS returned 10:11:15 (the month in the minutes slot), while HH24:MI:SS returned 10:30:15. With MI in TO_DATE, the row came back as 2026-11-28 10:30:15.

Setup
Setuprun as lab_a
CREATE TABLE login_logs (log_id NUMBER PRIMARY KEY, raw_time VARCHAR2(20));
INSERT INTO login_logs VALUES (1, '2026-11-28 10:30:15');
COMMIT;
OUTPUT
Table created.


1 row created.


Commit complete.
Reproducerun as lab_a
SELECT log_id, TO_DATE(raw_time, 'YYYY-MM-DD HH24:MM:SS') AS login_at FROM login_logs;
✕ ERROR
SELECT log_id, TO_DATE(raw_time, 'YYYY-MM-DD HH24:MM:SS') AS login_at FROM login_logs
                                 *
ERROR at line 1:
ORA-01810: format code appears twice
Help: https://docs.oracle.com/error-help/db/ora-01810/
Checkrun as lab_a
SELECT TO_CHAR(TO_DATE(raw_time, 'YYYY-MM-DD HH24:MI:SS'), 'HH24:MM:SS') AS with_mm, TO_CHAR(TO_DATE(raw_time, 'YYYY-MM-DD HH24:MI:SS'), 'HH24:MI:SS') AS with_mi FROM login_logs;
OUTPUT
WITH_MM  WITH_MI
-------- --------
10:11:15 10:30:15

1 row selected.

Search your code for HH24:MM and HH:MM. In TO_CHAR it silently prints the wrong value.

After the fixrun as lab_a
SELECT log_id, TO_CHAR(TO_DATE(raw_time, 'YYYY-MM-DD HH24:MI:SS'), 'YYYY-MM-DD HH24:MI:SS') AS login_at FROM login_logs;
✓ SUCCESS
    LOG_ID LOGIN_AT
---------- -------------------
         1 2026-11-28 10:30:15

1 row selected.

02Both AM and PM written in one mask

To read strings like '10:30 AM' and '02:15 PM', the mask HH:MI AM PM was used, and it failed with ORA-01810. AM and PM are the same element.

One of them is enough: TO_CHAR with HH:MI AM printed 14:15 as 02:15 PM, and TO_DATE(start_text, 'YYYY-MM-DD HH:MI AM') read both rows correctly as 10:30 and 14:15.

Setup
Setuprun as lab_a
CREATE TABLE shifts (shift_id NUMBER PRIMARY KEY, start_text VARCHAR2(20));
INSERT INTO shifts VALUES (1, '2026-11-28 10:30 AM');
INSERT INTO shifts VALUES (2, '2026-11-28 02:15 PM');
COMMIT;
OUTPUT
Table created.


1 row created.


1 row created.


Commit complete.
Reproducerun as lab_a
SELECT shift_id, TO_DATE(start_text, 'YYYY-MM-DD HH:MI AM PM') AS start_at FROM shifts;
✕ ERROR
SELECT shift_id, TO_DATE(start_text, 'YYYY-MM-DD HH:MI AM PM') AS start_at FROM shifts
                                     *
ERROR at line 1:
ORA-01810: format code appears twice
Help: https://docs.oracle.com/error-help/db/ora-01810/
Checkrun as lab_a
SELECT TO_CHAR(TO_DATE('2026-11-28 14:15', 'YYYY-MM-DD HH24:MI'), 'HH:MI AM') AS am_mask FROM dual;
OUTPUT
AM_MASK
--------
02:15 PM

1 row selected.

AM in the mask also accepts PM in the data (and the reverse). Write only one.

After the fixrun as lab_a
SELECT shift_id, TO_CHAR(TO_DATE(start_text, 'YYYY-MM-DD HH:MI AM'), 'YYYY-MM-DD HH24:MI') AS start_at FROM shifts ORDER BY shift_id;
✓ SUCCESS
  SHIFT_ID START_AT
---------- ----------------
         1 2026-11-28 10:30
         2 2026-11-28 14:15

2 rows selected.

03MM written twice in NLS_DATE_FORMAT

ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MM:SS' itself failed with ORA-01810.

The setting was not applied: nls_session_parameters still showed DD-MON-RR. Setting it with MI worked, and the DATE column displayed as 2026-11-28 10:30:15.

Setup
Setuprun as lab_a
CREATE TABLE orders (order_id NUMBER PRIMARY KEY, created_at DATE);
INSERT INTO orders VALUES (1, TO_DATE('2026-11-28 10:30:15', 'YYYY-MM-DD HH24:MI:SS'));
COMMIT;
OUTPUT
Table created.


1 row created.


Commit complete.
Reproducerun as lab_a
ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MM:SS';
✕ ERROR
ERROR:
ORA-01810: format code appears twice
Help: https://docs.oracle.com/error-help/db/ora-01810/
Checkrun as lab_a
COLUMN value FORMAT A20
SELECT value FROM nls_session_parameters WHERE parameter = 'NLS_DATE_FORMAT';
OUTPUT
VALUE
--------------------
DD-MON-RR

1 row selected.

If this ALTER SESSION runs in a login script or connection pool init and its error is ignored, dates keep showing in the default format.

After the fixrun as lab_a
ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS';
SELECT order_id, created_at FROM orders;
✓ SUCCESS
Session altered.


  ORDER_ID CREATED_AT
---------- -------------------
         1 2026-11-28 10:30:15

1 row selected.

FAQ

What does ORA-01810 format code appears twice mean?

The date format mask has two elements for the same field. Usually MM (month) was written where MI (minutes) was intended, as in HH24:MM:SS.

What is the Oracle format code for minutes?

MI. MM is the month. Use YYYY-MM-DD HH24:MI:SS.

Why does TO_CHAR with HH24:MM:SS show the wrong minutes without an error?

TO_CHAR accepts MM twice and prints the month in that position. For 10:30:15 in November it printed 10:11:15. Only TO_DATE raises ORA-01810.

How do I parse both AM and PM times in Oracle?

Write only AM (or only PM) in the mask: TO_DATE(str, 'YYYY-MM-DD HH:MI AM') reads both '10:30 AM' and '02:15 PM'.

How we verify

Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.

lab_a and lab_b are ordinary users created for the test; system is the DBA account. Oracle AI Database 26ai Free Release 23.26.3.0.0 - Develop, Learn, and Run for Free 23.26.3.0.0