// dialect comparison

Format a date as text in SQL Server, PostgreSQL, MySQL, SQLite and Oracle

The same format call does not translate across engines: the masks themselves are different languages.

Filed under Types & casting

The verdict

PostgreSQL and Oracle share TO_CHAR masks, MySQL and SQLite each have their own %-dialect, and SQL Server splits between fast style codes and slow .NET masks. Format at the presentation layer when possible.

Where they differ

Formatting a date for display is a per-engine dialect of its own. Each row renders the current date and time as yyyy-mm-dd hh:mi (for example 2026-11-20 14:30) in that engine's native idiom.

How each engine writes it

SQL Server

SELECT FORMAT(GETDATE(), 'yyyy-MM-dd HH:mm'), CONVERT(VARCHAR(16), GETDATE(), 120);

FORMAT uses .NET masks and is slow. CONVERT style 120 is the ODBC canonical yyyy-mm-dd hh:mi:ss layout; VARCHAR(16) cuts off the seconds.

PostgreSQL

SELECT TO_CHAR(NOW(), 'YYYY-MM-DD HH24:MI');

24-hour hours are HH24, not HH (HH is 12-hour). Minutes are MI.

MySQL

SELECT DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i');

% masks with a twist: minutes are %i (%m is month).

SQLite

SELECT STRFTIME('%Y-%m-%d %H:%M', 'now');

C-style strftime masks; only a fixed set of specifiers exists.

Oracle

SELECT TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI') FROM dual;

Same mask family as PostgreSQL. Without a mask, TO_CHAR uses NLS_DATE_FORMAT.

Questions that come up

Why does HH give me 02 when I expect 14?

In PostgreSQL and Oracle, HH is the 12-hour clock; HH24 is the 24-hour clock. MySQL's %H is already 24-hour.

What is the fastest way to format in SQL Server?

CONVERT with a style code: it is a built-in conversion with no CLR call. FORMAT is flexible but invokes .NET for every row.

Can one format string work everywhere?

Only by normalizing to a fixed ISO layout like yyyy-mm-dd, and even then you are choosing per engine between CONVERT style 120, TO_CHAR, DATE_FORMAT and strftime.

Keep reading

// write it once, run it anywhere

Switch engines without relearning SQL

SQLly is a native SQL workbench for macOS, Windows and Linux. Its formatter and plan viewer work in all five dialects.