Format dates with TO_CHAR

How TO_CHAR turns date values into formatted text in PostgreSQL and Oracle, what it changes, localization and padding pitfalls, and when to keep plain dates.

TO_CHAR is a SQL function that converts a date or timestamp into a text string according to a format model, such as 'YYYY-MM-DD' or 'Month DD, YYYY'. It is available in Oracle and PostgreSQL, among other databases. MySQL uses DATE_FORMAT and SQL Server uses FORMAT or CONVERT instead. This review covers what TO_CHAR changes, where its output works well, and where it causes problems for sorting, localization, and reuse. No test results or measurements were supplied for this article, so everything below describes documented behavior of the two main implementations, and you should check it against the version you run.

Is TO_CHAR suitable for your use?

TO_CHAR is a good fit when the formatted date is the final output: a report column, an export for people to read, a label in a generated message, or a file name. Its main benefit is precise, repeatable control over how a date looks, including localized month and day names.

The key tradeoff is that the result is text, not a date. Once a value passes through TO_CHAR, the database no longer treats it as a date. Sorting, range comparisons, date arithmetic, and index use all behave differently or stop working as expected. Keep the native date type when the value will be filtered, sorted, joined, or processed further. Format it only at the point where people read it. If the output must be readable by both machines and people across regions, an ISO-style 'YYYY-MM-DD' string is usually the safest text form.

What TO_CHAR actually changes

TO_CHAR does not modify stored data. It reads a date or timestamp value and returns a new string built from the format model. The table row is unchanged unless you write that string back into a column. The function also performs no visual effects such as mirroring, reversal, or Unicode character substitution. The output consists of ordinary characters: digits, separators, and words taken from the session's language settings.

-- PostgreSQL
SELECT to_char(timestamp '2026-03-04 14:05:09', 'YYYY-MM-DD HH24:MI:SS');
-- 2026-03-04 14:05:09

SELECT to_char(date '2026-03-04', 'MM/DD/YYYY');
-- 03/04/2026

-- Oracle
SELECT TO_CHAR(DATE '2026-03-04', 'FMMonth DD, YYYY') FROM dual;
-- March 4, 2026

Each element of the format model is replaced by part of the date. Characters that are not recognized patterns, such as hyphens, slashes, colons, and commas, pass through as written. To include literal words, enclose them in double quotes inside the format string.

Pattern | Produces | Note
YYYY | Four-digit year | IYYY is the ISO week-numbering year, which can differ near January 1
MM | Month number, 01–12 | Not minutes
MI | Minutes, 00–59 | A common source of mix-ups with MM
DD | Day of month, 01–31 | DDD is day of year
HH24 | Hour, 00–23 | HH and HH12 give a 12-hour clock; pair them with AM or PM
SS | Seconds, 00–59 |
Month / MONTH / month | Full month name | Capitalization of the pattern controls capitalization of the output
Mon | Abbreviated month name |
Day / Dy | Full or abbreviated weekday name |
FM | Fill mode modifier | Suppresses padding; scope differs between Oracle and PostgreSQL

Common format mistakes

  • Writing 'HH:MM:SS' for a time. MM repeats the month, and HH is a 12-hour clock. Use 'HH24:MI:SS'.
  • Forgetting padding. Name patterns such as Month and Day are blank-padded to a fixed width by default. In PostgreSQL, 'Month DD, YYYY' for March gives 'March 04, 2026', with the name padded to nine characters. Trailing spaces like these can break equality checks and look wrong in sentences.
  • Assuming FM works the same everywhere. In PostgreSQL, FM affects only the pattern that follows it, so 'FMMonth FMDD, YYYY' is needed to get 'March 4, 2026'. In Oracle, FM toggles fill mode for the rest of the format, so 'FMMonth DD, YYYY' already gives 'March 4, 2026'.
  • Mixing YYYY with IW. ISO week numbers belong with the ISO year (IYYY). Combining a calendar year with an ISO week can produce mismatched labels in the last and first days of a year.

Localization of dates

Numeric order is set entirely by the format model. TO_CHAR does not adapt 'MM/DD/YYYY' to a reader's region. That order is common in the US, but '03/04/2026' reads as April 3 in many other countries. When an audience is mixed or unknown, either use 'YYYY-MM-DD' or spell out the month so the order cannot be misread.

Month and day names depend on language settings. In Oracle, an optional third argument sets the language for a single call, as in TO_CHAR(d, 'FMMonth', 'NLS_DATE_LANGUAGE = French'). Otherwise, the session's NLS settings apply. In PostgreSQL, names are in English unless you add the TM (translation mode) prefix, as in 'TMMonth'. TM then uses the lc_time setting. In both systems, the same query can therefore return different words on different servers or sessions. Set the language explicitly when consistent output matters.

Time zones also affect the result. In PostgreSQL, a timestamp with time zone is rendered in the session's TimeZone setting before formatting. Oracle's DATE type stores no time zone at all. If the reader's time zone matters, convert the value deliberately before formatting, and include an offset or zone pattern in the output where the database supports one.

Readability after copying or sharing

Numeric formats contain only basic characters, so they generally copy and paste cleanly. Localized month names may include accented letters, which depend on correct character encoding in the destination. These are documented properties of the output. No destination-specific tests were supplied for this article.

The bigger risk is reinterpretation. A formatted string is just text. Spreadsheets and import tools may try to parse date-like text using their own locale rules, which can swap day and month or silently change the value. Loading the text back into a database requires TO_DATE or to_timestamp with a matching format model. When data will be re-imported, an ISO 'YYYY-MM-DD' string, or the original date value, is less ambiguous than a regional numeric form.

Sorting also changes once the value is text. Text sorts character by character. 'YYYY-MM-DD' sorts in chronological order, but 'MM/DD/YYYY' or spelled-out month names do not. Search and filtering likewise become string matching, not date ranges.

For accessibility, a spelled-out month such as 'March 4, 2026' gives a reader, or a screen reader, an unambiguous date. A numeric form relies on the reader knowing the intended order. How specific assistive technologies announce numeric or abbreviated dates was not tested here and varies by product and settings. If accessibility is a requirement, verify the output with the assistive technology your audience uses rather than assuming one rendering applies everywhere. In web pages, keeping a machine-readable date alongside the formatted text is a common way to serve both needs.

Bottom line

Use TO_CHAR at the display or export edge, where you need exact control over how a date reads, including localized names. Keep native date values for anything that is sorted, compared, calculated, or re-imported. When the audience spans regions, prefer 'YYYY-MM-DD' or a spelled-out month. Set FM, the language, and the time zone explicitly so the output stays the same across sessions and servers.