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

ORA-01821: date format not recognized

The format mask has an element Oracle doesn't accept for this value: an unknown code, or a TIMESTAMP-only code used with DATE.

Oracle AI Database 26ai Free 23.26.3.0.0
ORA-01821: date format not recognized

Jump to a cause

  1. 01FF3 (milliseconds) used on a DATE column
  2. 02'ms' copied from another language's date format
  3. 03TZR (time zone) used on a DATE column

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-01821 means Oracle can't use the format mask you gave TO_CHAR or TO_DATE. Either the code doesn't exist in Oracle (like 'ms'), or it exists only for TIMESTAMP types and the value is a DATE. DATE stores seconds at most and has no time zone, so FF (fractional seconds) and TZR are rejected.

All three common cases were reproduced and fixed below.

01FF3 (milliseconds) used on a DATE column

TO_CHAR(logged_at, 'YYYY-MM-DD HH24:MI:SS.FF3') failed with ORA-01821. user_tab_columns showed LOGGED_AT is DATE, while LOGGED_TS is TIMESTAMP(3).

Dropping FF3 for the DATE column and using it only on the TIMESTAMP column returned 2026-11-28 10:30:15 and 2026-11-28 10:30:15.250.

Setup
Setuprun as lab_a
CREATE TABLE api_logs (log_id NUMBER PRIMARY KEY, logged_at DATE, logged_ts TIMESTAMP(3));
INSERT INTO api_logs VALUES (1, TO_DATE('2026-11-28 10:30:15', 'YYYY-MM-DD HH24:MI:SS'), TO_TIMESTAMP('2026-11-28 10:30:15.250', 'YYYY-MM-DD HH24:MI:SS.FF3'));
COMMIT;
OUTPUT
Table created.


1 row created.


Commit complete.
Reproducerun as lab_a
SELECT log_id, TO_CHAR(logged_at, 'YYYY-MM-DD HH24:MI:SS.FF3') AS logged FROM api_logs;
✕ ERROR
SELECT log_id, TO_CHAR(logged_at, 'YYYY-MM-DD HH24:MI:SS.FF3') AS logged FROM api_logs
                                  *
ERROR at line 1:
ORA-01821: date format not recognized
Help: https://docs.oracle.com/error-help/db/ora-01821/
Checkrun as lab_a
COLUMN column_name FORMAT A10
COLUMN data_type FORMAT A12
SELECT column_name, data_type FROM user_tab_columns WHERE table_name = 'API_LOGS' AND column_name LIKE 'LOGGED%' ORDER BY column_id;
OUTPUT
COLUMN_NAM DATA_TYPE
---------- ------------
LOGGED_AT  DATE
LOGGED_TS  TIMESTAMP(3)

2 rows selected.

If you need milliseconds, the column has to be TIMESTAMP. A DATE never had them to begin with.

After the fixrun as lab_a
SELECT log_id, TO_CHAR(logged_at, 'YYYY-MM-DD HH24:MI:SS') AS logged, TO_CHAR(logged_ts, 'YYYY-MM-DD HH24:MI:SS.FF3') AS logged_ms FROM api_logs;
✓ SUCCESS
    LOG_ID LOGGED              LOGGED_MS
---------- ------------------- -----------------------
         1 2026-11-28 10:30:15 2026-11-28 10:30:15.250

1 row selected.

02'ms' copied from another language's date format

The string '2026-11-28 10:30:15:250' was read with TO_DATE(raw_time, 'yyyy-mm-dd hh24:mi:ss:ms') and failed with ORA-01821. Oracle has no 'ms' format code.

If milliseconds aren't needed, take the first 19 characters and convert to DATE: 2026-11-28 10:30:15. To keep them, TO_TIMESTAMP(raw_time, 'YYYY-MM-DD HH24:MI:SS:FF3') returned 2026-11-28 10:30:15.250.

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


1 row created.


Commit complete.
Reproducerun as lab_a
SELECT event_id, TO_DATE(raw_time, 'yyyy-mm-dd hh24:mi:ss:ms') AS event_time FROM events;
✕ ERROR
SELECT event_id, TO_DATE(raw_time, 'yyyy-mm-dd hh24:mi:ss:ms') AS event_time FROM events
                                   *
ERROR at line 1:
ORA-01821: date format not recognized
Help: https://docs.oracle.com/error-help/db/ora-01821/
Checkrun as lab_a
SELECT event_id, TO_CHAR(TO_DATE(SUBSTR(raw_time, 1, 19), 'YYYY-MM-DD HH24:MI:SS'), 'YYYY-MM-DD HH24:MI:SS') AS no_ms FROM events;
OUTPUT
  EVENT_ID NO_MS
---------- -------------------
         1 2026-11-28 10:30:15

1 row selected.

Fractional seconds in Oracle are FF (FF1 to FF9), and only for TO_TIMESTAMP and TIMESTAMP values.

After the fixrun as lab_a
SELECT event_id, TO_CHAR(TO_TIMESTAMP(raw_time, 'YYYY-MM-DD HH24:MI:SS:FF3'), 'YYYY-MM-DD HH24:MI:SS.FF3') AS event_time FROM events;
✓ SUCCESS
  EVENT_ID EVENT_TIME
---------- -----------------------
         1 2026-11-28 10:30:15.250

1 row selected.

03TZR (time zone) used on a DATE column

TO_CHAR(created_at, 'YYYY-MM-DD HH24:MI:SS TZR') failed with ORA-01821. CREATED_AT is DATE, which carries no time zone.

FROM_TZ(CAST(created_at AS TIMESTAMP), 'Asia/Seoul') attaches a zone, and the same mask then returned 2026-11-28 10:30:15 ASIA/SEOUL.

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
SELECT order_id, TO_CHAR(created_at, 'YYYY-MM-DD HH24:MI:SS TZR') AS created FROM orders;
✕ ERROR
SELECT order_id, TO_CHAR(created_at, 'YYYY-MM-DD HH24:MI:SS TZR') AS created FROM orders
                                     *
ERROR at line 1:
ORA-01821: date format not recognized
Help: https://docs.oracle.com/error-help/db/ora-01821/
Checkrun as lab_a
COLUMN column_name FORMAT A10
COLUMN data_type FORMAT A10
SELECT column_name, data_type FROM user_tab_columns WHERE table_name = 'ORDERS' AND column_name = 'CREATED_AT';
OUTPUT
COLUMN_NAM DATA_TYPE
---------- ----------
CREATED_AT DATE

1 row selected.

FROM_TZ only labels the value with a zone; it does not convert the time. Use the zone the data was actually recorded in.

After the fixrun as lab_a
SELECT order_id, TO_CHAR(FROM_TZ(CAST(created_at AS TIMESTAMP), 'Asia/Seoul'), 'YYYY-MM-DD HH24:MI:SS TZR') AS created FROM orders;
✓ SUCCESS
  ORDER_ID CREATED
---------- ----------------------------------------------------
         1 2026-11-28 10:30:15 ASIA/SEOUL

1 row selected.

FAQ

What does ORA-01821 date format not recognized mean?

The format mask contains a code Oracle doesn't know (like 'ms') or one that only works with TIMESTAMP (like FF or TZR) used on a DATE.

How do I show milliseconds of a DATE in Oracle?

You can't; DATE stores up to seconds. Store the value as TIMESTAMP and use FF3, e.g. TO_CHAR(ts_col, 'YYYY-MM-DD HH24:MI:SS.FF3').

What is the Oracle format for milliseconds?

FF3 (FF1-FF9 for other precisions), with TO_TIMESTAMP or a TIMESTAMP value. 'ms' gives ORA-01821.

How do I add a time zone to a DATE value?

Use FROM_TZ(CAST(date_col AS TIMESTAMP), 'Asia/Seoul'), then TZR works in TO_CHAR.

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