Date Format Cheat Sheet · Tutorial
How to format dates in MySQL with DATE_FORMAT
4 min readbeginnerUpdated
A report query needs order dates as 04 Mar 2026 and an export needs 2026-03-04 15:07:09. With the MySQL table of the cheat sheet, you'll pick the codes, avoid the codes that differ from other languages, and copy the patterns into your query.
What you need
- The Date Format Cheat Sheet with the MySQL table selected
- A table with a DATE or DATETIME column
Steps
Open the MySQL table
Choose SQL: MySQL / MariaDB (DATE_FORMAT). The usage line shows the function call.
DATE_FORMAT(created_at, '%Y-%m-%d')Build a short date
Use
%dfor the 2-digit day,%bfor the short month name and%Yfor the year, which prints04 Mar 2026.SELECT DATE_FORMAT(created_at, '%d %b %Y') FROM orders;Watch the minutes
In MySQL
%Mis the month name, and minutes are%i. The SQL datetime format is%Y-%m-%d %H:%i:%s.Copy a common format
Copy patterns from Common formats and check the Example column before running the query.
Try it yourself
Opens the Date Format Cheat Sheet with this tutorial's sample loaded.
Common mistakes
- Using %M for minutes
- This prints
Marchwhere you expected07. Use%i. - Expecting time zone codes
DATE_FORMAThas no code for the UTC offset. Convert withCONVERT_TZand add the offset as text if needed.- Unix timestamps
- For epoch seconds use
UNIX_TIMESTAMP(created_at)rather than a format code.
Next steps
Go back to the Date Format Cheat Sheet, or keep going with one of these: