Formatting a date, number, or other value as a string according to a format pattern.
PostgreSQL and Oracle function that converts dates, numbers, and timestamps to formatted strings. Supports a wide range of format patterns for locale-aware output. The most flexible formatting function across databases.
| Database System | Support Status | Since Version | Notes |
|---|---|---|---|
| MySQL | ✓ Supported | 5.0 | DATE_FORMAT() for date/datetime values; FORMAT() for numbers (adds thousands separator). No unified TO_CHAR equivalent. |
| PostgreSQL | ✓ Supported | 7.4 | TO_CHAR() handles dates, timestamps, numbers, and intervals with a rich pattern language. TO_DATE() and TO_NUMBER() are the inverse functions. |
| SQL Server | ✓ Supported | 2012 | FORMAT() added in 2012 using .NET format strings. CONVERT() with a style code is the older approach and works on all versions. FORMAT() is convenient but notably slower than CONVERT() at scale. |
| Oracle | ✓ Supported | 7 | TO_CHAR() is the standard for both dates and numbers. NLS session parameters can affect output; use explicit format masks to ensure consistency. |
| SQLite | ✓ Supported | 3.0.0 | strftime() handles date formatting. For numeric formatting, use printf() / format(), available since 3.38.0. |
Date and number formatting is one of the most fragmented areas across SQL engines. PostgreSQL and Oracle share TO_CHAR() with similar (but not identical) pattern languages — Oracle's format tokens are case-sensitive in some contexts; PostgreSQL is case-insensitive. SQL Server's FORMAT() uses .NET composite format strings, which are powerful but measurably slower than CONVERT() for high-volume queries. MySQL splits the concern: DATE_FORMAT() for dates, FORMAT() for numbers. SQLite uses Unix-style strftime() for dates and printf() for numbers. For cross-engine portability, CAST(value AS VARCHAR/TEXT) plus application-layer formatting is often simpler than maintaining five different format strings.
DATE_FORMAT() for date/datetime values; FORMAT() for numbers (adds thousands separator). No unified TO_CHAR equivalent.
TO_CHAR() handles dates, timestamps, numbers, and intervals with a rich pattern language. TO_DATE() and TO_NUMBER() are the inverse functions.
FORMAT() added in 2012 using .NET format strings. CONVERT() with a style code is the older approach and works on all versions. FORMAT() is convenient but notably slower than CONVERT() at scale.
TO_CHAR() is the standard for both dates and numbers. NLS session parameters can affect output; use explicit format masks to ensure consistency.
strftime() handles date formatting. For numeric formatting, use printf() / format(), available since 3.38.0.