DATE_FORMAT() in MySQL — How It Works

What the MySQL DATE_FORMAT() function does, with an example.

Published October 19, 2026

DATE_FORMAT(date, format) formats a date or datetime as a string using specifiers such as %Y, %m, %d, %H and %i.

How it works

The reverse is STR_TO_DATE.

Try it in MySQL

SELECT DATE_FORMAT('2026-11-12', '%d/%m/%Y')
12/11/2026
SELECT DATE_FORMAT(NOW(), '%W, %M %e')
Thursday, November 12
SELECT DATE_FORMAT(NOW(), '%Y-%m')
2026-11

Practical examples

Example 1

SELECT DATE_FORMAT('2026-11-12', '%d/%m/%Y');
-- 12/11/2026

Example 2

SELECT DATE_FORMAT(NOW(), '%W, %M %e');
-- Thursday, November 12

Example 3

SELECT DATE_FORMAT(NOW(), '%Y-%m');
-- 2026-11

Use it in a real query

SELECT id, DATE_FORMAT('2026-11-12', '%d/%m/%Y') AS result
FROM your_table
LIMIT 10;

Common mistakes

  • Mixing up %m (month) and %i (minutes).
  • Formatting in SQL when the app could do it.
  • Grouping by formatted strings without an index.

Key takeaways

  • DATE_FORMAT() in one line: DATE_FORMAT(date, format) formats a date or datetime as a string using specifiers such as %Y, %m, %d, %H and %i.
  • Try queries in a test database first.
  • Check NULL handling and data types.

FAQ

Month names?

%M for the full name, %b for abbreviated.

Does DATE_FORMAT() work in other databases?

Most have an equivalent, but names and syntax vary between MySQL, PostgreSQL, SQL Server and SQLite.

More SQL articles