How to Format Dates in MySQL
Last updated July 25, 2026 · By the SaturnSQL team
Use DATE_FORMAT(date, format) with % specifiers: '%Y-%m-%d' gives 2026-07-25, '%M %e, %Y' gives July 25, 2026. DATE_FORMAT returns a string, so use it for display and grouping labels, not for comparisons on indexed columns.
SELECT DATE_FORMAT(created_at, '%Y-%m-%d') AS day,
DATE_FORMAT(created_at, '%M %e, %Y') AS pretty,
DATE_FORMAT(created_at, '%H:%i') AS hhmm
FROM orders;Common specifiers
%Y four-digit year, %m month 01-12, %d day 01-31, %H hour 00-23, %i minutes, %s seconds, %M month name, %W weekday name, %e day without leading zero.
Group by month
SELECT DATE_FORMAT(created_at, '%Y-%m') AS month,
COUNT(*) AS orders
FROM orders
GROUP BY month
ORDER BY month;Run this in SaturnSQL
SaturnSQL is a browser-based SQL editor for teams: shared query library, schema-aware autocomplete, and scheduled exports to Google Sheets and Slack.
Try it free