PostgreSQL TO_CHAR() to MySQL DATE_FORMAT() Converter
Paste a PostgreSQL TO_CHAR() template to get the equivalent MySQL DATE_FORMAT() specifier string.
Requires review Works only under specific conditions — read the caveats before relying on it.
- PostgreSQL TO_CHAR()
YYYY-MM-DD HH24:MI:SS- MySQL DATE_FORMAT()
%Y-%m-%d %H:%i:%s
Main limitation: Postgres's blank-padded `Day`/`Month` (9-character fixed width) are intentionally left unmapped in favor of their `FM`-prefixed forms (`FMDay`, `FMMonth`), which convert cleanly to MySQL's `%W`/`%M`.
How it differs
- Postgres's blank-padded
Day/Month(9-character fixed width) are intentionally left unmapped in favor of theirFM-prefixed forms (FMDay,FMMonth), which convert cleanly to MySQL's%W/%M. - Postgres's
TH/thordinal-suffix modifier attaches to whatever field precedes it (e.g.FMDDth); this engine does not model attached modifiers, so it is reported as unsupported rather than silently fused into MySQL's%D. - Postgres has separate
MS(milliseconds) andUS(microseconds) tokens that map directly to MySQL's%f(microseconds) and PHP/date-fns equivalents — MySQL itself has no milliseconds-only specifier.
Examples
Standard timestamp
| PostgreSQL TO_CHAR() | YYYY-MM-DD HH24:MI:SS |
|---|---|
| MySQL DATE_FORMAT() | %Y-%m-%d %H:%i:%s |
A direct, exact mapping for a typical timestamp column format.
Ordinal-suffix modifier (partial conversion)
| PostgreSQL TO_CHAR() | FMDay, FMDDth FMMonth YYYY |
|---|---|
| MySQL DATE_FORMAT() | %W, %e %M %Y |
The `th` ordinal-suffix modifier has no standalone MySQL equivalent and is dropped with a warning; `FMDD` converts to MySQL's non-padded `%e` on its own.
Edge cases
Edge case
Use FMDD (not DD) immediately before FMMonth/FMDay if you want MySQL's combined %D — this converter only fuses FMDD + the literal ordinal-suffix pattern automatically for MySQL's adjacent-pair rule; a bare TH/th modifier is flagged, not fused.
Edge case
Postgres's ID (ISO day of week) and IW (ISO week of year) map to MySQL specifiers that are close but not certified identical across all MySQL week modes — verify against %v/%u if week-boundary precision matters.
References
- PostgreSQL docs — Data Type Formatting Functions (to_char) (v17) — checked 2026-07-29
- MySQL Reference Manual — DATE_FORMAT() (v8.4) — checked 2026-07-29
Last verified 2026-07-29.