Oracle Date Format Builder: TO_CHAR / TO_DATE Format Masks
Type or click together an Oracle datetime format mask and see exactly what TO_CHAR returns for your date, with NLS_DATE_LANGUAGE = AMERICAN. The tool splits masks the way Oracle does, by longest element match, so MONTH, MI vs MM, HH24 and DDD are read correctly, and it applies Oracle's rules for blank-padded MONTH and DAY names, the FM fill-mode toggle, upper/Initcap/lower case, TH, SP and SPTH suffixes, FF1-FF9 fractional seconds, ISO and WW weeks, J Julian days and the RR century rule. A table renders 28 common masks with copy-ready SELECT TO_CHAR and TO_DATE / TO_TIMESTAMP statements, and a string-to-mask helper tells you which format parses a date string, including the ORA error you would get otherwise. Everything runs in your browser.
TO_CHAR format mask builder
Datetime format element reference (live values)
| Element | Meaning | Example |
|---|---|---|
| YYYY | 4-digit year | 2026 |
| YYY | last 3 digits | 026 |
| YY | last 2 digits | 26 |
| Y | last digit | 6 |
| RRRR | year (RR rule on input) | 2026 |
| RR | 2-digit year, RR rule | 26 |
| SYYYY | signed year, BC negative | 2026 |
| Y,YYY | year with comma | 2,026 |
| IYYY | ISO week-year | 2026 |
| CC | century | 21 |
| YEAR | spelled out | TWENTY TWENTY-SIX |
| Q | quarter 1-4 | 1 |
| MM | 01-12 | 03 |
| MON | MAR | MAR |
| Mon | Mar | Mar |
| MONTH | MARCH, padded to 9 | MARCH |
| Month | March, padded to 9 | March |
| month | march | march |
| RM | Roman numeral | III |
| WW | week of year, 7-day blocks from Jan 1 | 10 |
| W | week of month, blocks from the 1st | 1 |
| IW | ISO week 1-53 | 10 |
| DD | day of month | 05 |
| DDD | day of year | 064 |
| D | day of week, Sunday = 1 | 5 |
| DY | THU | THU |
| Dy | Thu | Thu |
| DAY | THURSDAY, padded to 9 | THURSDAY |
| Day | Thursday, padded to 9 | Thursday |
| J | Julian day | 2461105 |
| HH24 | hour 00-23 | 14 |
| HH | hour 01-12 | 02 |
| HH12 | hour 01-12 | 02 |
| MI | minutes | 07 |
| SS | seconds | 09 |
| SSSSS | seconds past midnight | 50829 |
| FF3 | milliseconds | 123 |
| FF6 | microseconds | 123456 |
| FF | type precision | 123456 |
| X | radix character | . |
| AM | meridian | PM |
| A.M. | meridian with dots | P.M. |
| FMDD | toggle fill mode (no padding) | 5 |
| FXDD | exact match for TO_DATE | 05 |
| DDTH | ordinal suffix | 05TH |
| DDSP | spell out | FIVE |
| DDSPTH | spelled ordinal | FIFTH |
| AD | era | AD |
| DS | short date (territory) | 03/05/2026 |
| DL | long date (territory) | Thursday, March 5, 2026 |
Common Oracle date format masks
| Mask | Output | TO_CHAR | Back to a date |
|---|---|---|---|
Default NLS_DATE_FORMAT (AMERICA) | 05-MAR-26 | SELECT TO_CHAR(SYSDATE, 'DD-MON-YY') FROM dual; | SELECT TO_DATE('05-MAR-26', 'DD-MON-YY') FROM dual; |
Default with the RR century rule | 05-MAR-26 | SELECT TO_CHAR(SYSDATE, 'DD-MON-RR') FROM dual; | SELECT TO_DATE('05-MAR-26', 'DD-MON-RR') FROM dual; |
Day-month-year with 4-digit year | 05-MAR-2026 | SELECT TO_CHAR(SYSDATE, 'DD-MON-YYYY') FROM dual; | SELECT TO_DATE('05-MAR-2026', 'DD-MON-YYYY') FROM dual; |
Date + 24-hour time | 05-MAR-2026 14:07:09 | SELECT TO_CHAR(SYSDATE, 'DD-MON-YYYY HH24:MI:SS') FROM dual; | SELECT TO_DATE('05-MAR-2026 14:07:09', 'DD-MON-YYYY HH24:MI:SS') FROM dual; |
ISO 8601 date | 2026-03-05 | SELECT TO_CHAR(SYSDATE, 'YYYY-MM-DD') FROM dual; | SELECT TO_DATE('2026-03-05', 'YYYY-MM-DD') FROM dual; |
ISO date + 24-hour time | 2026-03-05 14:07:09 | SELECT TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS') FROM dual; | SELECT TO_DATE('2026-03-05 14:07:09', 'YYYY-MM-DD HH24:MI:SS') FROM dual; |
ISO 8601 with T separator | 2026-03-05T14:07:09 | SELECT TO_CHAR(SYSDATE, 'YYYY-MM-DD"T"HH24:MI:SS') FROM dual; | SELECT TO_DATE('2026-03-05T14:07:09', 'YYYY-MM-DD"T"HH24:MI:SS') FROM dual; |
Timestamp with milliseconds | 2026-03-05 14:07:09.123 | SELECT TO_CHAR(SYSTIMESTAMP, 'YYYY-MM-DD HH24:MI:SS.FF3') FROM dual; | SELECT TO_TIMESTAMP('2026-03-05 14:07:09.123', 'YYYY-MM-DD HH24:MI:SS.FF3') FROM dual; |
Timestamp with microseconds | 2026-03-05 14:07:09.123456 | SELECT TO_CHAR(SYSTIMESTAMP, 'YYYY-MM-DD HH24:MI:SS.FF6') FROM dual; | SELECT TO_TIMESTAMP('2026-03-05 14:07:09.123456', 'YYYY-MM-DD HH24:MI:SS.FF6') FROM dual; |
Default NLS_TIMESTAMP_FORMAT (AMERICA) | 05-MAR-26 02.07.09.123456 PM | SELECT TO_CHAR(SYSTIMESTAMP, 'DD-MON-RR HH.MI.SSXFF AM') FROM dual; | SELECT TO_TIMESTAMP('05-MAR-26 02.07.09.123456 PM', 'DD-MON-RR HH.MI.SSXFF AM') FROM dual; |
European / UK date | 05/03/2026 | SELECT TO_CHAR(SYSDATE, 'DD/MM/YYYY') FROM dual; | SELECT TO_DATE('05/03/2026', 'DD/MM/YYYY') FROM dual; |
European date + time | 05/03/2026 14:07:09 | SELECT TO_CHAR(SYSDATE, 'DD/MM/YYYY HH24:MI:SS') FROM dual; | SELECT TO_DATE('05/03/2026 14:07:09', 'DD/MM/YYYY HH24:MI:SS') FROM dual; |
US date | 03/05/2026 | SELECT TO_CHAR(SYSDATE, 'MM/DD/YYYY') FROM dual; | SELECT TO_DATE('03/05/2026', 'MM/DD/YYYY') FROM dual; |
US date + 12-hour time | 03/05/2026 02:07:09 PM | SELECT TO_CHAR(SYSDATE, 'MM/DD/YYYY HH:MI:SS AM') FROM dual; | SELECT TO_DATE('03/05/2026 02:07:09 PM', 'MM/DD/YYYY HH:MI:SS AM') FROM dual; |
German date | 05.03.2026 | SELECT TO_CHAR(SYSDATE, 'DD.MM.YYYY') FROM dual; | SELECT TO_DATE('05.03.2026', 'DD.MM.YYYY') FROM dual; |
Compact date | 20260305 | SELECT TO_CHAR(SYSDATE, 'YYYYMMDD') FROM dual; | SELECT TO_DATE('20260305', 'YYYYMMDD') FROM dual; |
Compact date-time | 20260305140709 | SELECT TO_CHAR(SYSDATE, 'YYYYMMDDHH24MISS') FROM dual; | SELECT TO_DATE('20260305140709', 'YYYYMMDDHH24MISS') FROM dual; |
Long date (names blank-padded) | Thursday , 05 March 2026 | SELECT TO_CHAR(SYSDATE, 'Day, DD Month YYYY') FROM dual; | SELECT TO_DATE('Thursday , 05 March 2026', 'Day, DD Month YYYY') FROM dual; |
Long date with FM (no padding) | Thursday, 5 March 2026 | SELECT TO_CHAR(SYSDATE, 'FMDay, DD Month YYYY') FROM dual; | SELECT TO_DATE('Thursday, 5 March 2026', 'FMDay, DD Month YYYY') FROM dual; |
US long date | March 5, 2026 | SELECT TO_CHAR(SYSDATE, 'FMMonth DD, YYYY') FROM dual; | SELECT TO_DATE('March 5, 2026', 'FMMonth DD, YYYY') FROM dual; |
Short month name | Mar 05, 2026 | SELECT TO_CHAR(SYSDATE, 'Mon DD, YYYY') FROM dual; | SELECT TO_DATE('Mar 05, 2026', 'Mon DD, YYYY') FROM dual; |
RFC 2822 style (no zone) | Thu, 05 Mar 2026 14:07:09 | SELECT TO_CHAR(SYSDATE, 'Dy, DD Mon YYYY HH24:MI:SS') FROM dual; | SELECT TO_DATE('Thu, 05 Mar 2026 14:07:09', 'Dy, DD Mon YYYY HH24:MI:SS') FROM dual; |
Ordinal day | 5th of March 2026 | SELECT TO_CHAR(SYSDATE, 'FMDdth "of" Month YYYY') FROM dual; | SELECT TO_DATE('5th of March 2026', 'FMDdth "of" Month YYYY') FROM dual; |
24-hour time | 14:07:09 | SELECT TO_CHAR(SYSDATE, 'HH24:MI:SS') FROM dual; | SELECT TO_DATE('14:07:09', 'HH24:MI:SS') FROM dual; |
12-hour time | 02:07 PM | SELECT TO_CHAR(SYSDATE, 'HH:MI AM') FROM dual; | SELECT TO_DATE('02:07 PM', 'HH:MI AM') FROM dual; |
ISO week | 2026-W10 | SELECT TO_CHAR(SYSDATE, 'IYYY-"W"IW') FROM dual; | ORA-01820: format code cannot appear in date input format (IYYY can only be used with TO_CHAR) |
Quarter | 2026-Q1 | SELECT TO_CHAR(SYSDATE, 'YYYY-"Q"Q') FROM dual; | ORA-01820: format code cannot appear in date input format (Q can only be used with TO_CHAR) |
Julian day number | 2461105 | SELECT TO_CHAR(SYSDATE, 'J') FROM dual; | SELECT TO_DATE('2461105', 'J') FROM dual; |
String to date: which mask parses it?
| Mask | Parsed as | Match |
|---|---|---|
| DD-MON-YYYY HH24:MI:SS | 2026-03-05 14:07:09 | Exact (FX) |
| DD/MM/YYYY HH24:MI:SS | 2026-03-05 14:07:09 | Lenient |
Do more than oracle date format builder: to_char / to_date format masks — meet Chat2DB
Chat2DB is an AI-powered SQL client for Windows, macOS and Linux. Write SQL in natural language, format and optimize queries automatically, and manage MySQL, PostgreSQL, Oracle and 20+ other databases in one workspace.
How to use
- Enter a datetime (YYYY-MM-DD HH:MI:SS.fffffffff, it defaults to now), choose DATE or TIMESTAMP, and type a format mask or click element buttons such as YYYY, MON, DD, HH24 and FM.
- Check the TO_CHAR preview (padding is shown as-is) and copy the generated SELECT TO_CHAR, TO_DATE and ALTER SESSION SET NLS_DATE_FORMAT statements, or pick a ready-made mask from the common masks table.
- Paste a date string into the string-to-mask helper to see which masks parse it, whether it also passes the strict FX mode, and copy the TO_DATE statements.
Frequently asked questions
Why does TO_CHAR(date, 'Month') add trailing spaces in Oracle?
MONTH and DAY are blank-padded to the length of the longest name in the date language, 9 characters in English (SEPTEMBER, WEDNESDAY), so 'Month DD' gives 'March 05'. Put the FM modifier in front ('FMMonth DD, YYYY' gives 'March 5, 2026') to remove the padding and the leading zeros. FM is a toggle: a second FM in the same mask turns padding back on. The case of the mask controls the output: MONTH gives MARCH, Month gives March and month gives march.
What is the difference between YY and RR, and between MM and MI, in Oracle date formats?
In TO_DATE, YY puts a two-digit year into the current century, while RR picks the century closest to now: with the current year 2026, '75' becomes 1975 under RR but 2075 under YY. For TO_CHAR both print the last two digits. MM is the month (01-12) and MI is minutes; mixing them up is a classic bug, as is using HH (12-hour) without AM when you meant HH24. The default NLS_DATE_FORMAT for the AMERICA territory is DD-MON-RR.
How do I fix ORA-01861 and ORA-01843 when converting strings with TO_DATE?
ORA-01861 (literal does not match format string) means the text and the mask disagree, for example quoted text such as "T" is missing or there is extra text; ORA-01843 (not a valid month) means the month position holds a number above 12 or a month name that is not valid in the session language. Always pass an explicit mask, add 'NLS_DATE_LANGUAGE=AMERICAN' for month names, and in Oracle 12.2+ use DEFAULT NULL ON CONVERSION ERROR or VALIDATE_CONVERSION to find bad rows. Chat2DB, a free AI-powered SQL client for Oracle, lets you run and compare these conversions quickly: download it at https://chat2db.ai/download or use the web version at https://app.chat2db.ai.
