Smart SQL Tools for Every Database

MySQL Function Reference

MySQL DATE_FORMAT() Function

Learn how to use the MySQL DATE_FORMAT date function with practical examples and cross-dialect alternatives.

Back to SQL Function Explorer

Syntax

DATE_FORMAT(date, format)

DATE_FORMAT returns a formatted string from a date or datetime value.

Basic Example

SELECT DATE_FORMAT('2026-05-17', '%Y-%m-%d') AS iso_date;
    -- Result: 2026-05-17

Practical query example

SELECT DATE_FORMAT(created_at, '%Y-%m') AS month_bucket,
       COUNT(*) AS orders_count
    FROM orders
    GROUP BY DATE_FORMAT(created_at, '%Y-%m')
    ORDER BY month_bucket;

Useful format tokens

%Y = 4-digit year
    %m = 2-digit month
    %d = 2-digit day
    %H = hour (00-23)
    %i = minutes (00-59)
    %s = seconds (00-59)

When to use it

Use DATE_FORMAT for dashboards, export labels, monthly grouping keys, and user-facing date strings in MySQL queries.

Common mistakes

Cross-dialect alternatives

Troubleshoot MySQL DATE_FORMAT problems

Related SQL Functions

FAQ

Why does YYYY-MM-DD not work as expected?

MySQL DATE_FORMAT uses percent-style tokens, so use %Y-%m-%d instead.

Does DATE_FORMAT return DATE or VARCHAR?

It returns a formatted string value, not a native DATE type.

Can DATE_FORMAT affect query performance?

Yes. Wrapping indexed columns in functions can reduce index usage in WHERE clauses.