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

Steps

  1. Open the MySQL table

    Choose SQL: MySQL / MariaDB (DATE_FORMAT). The usage line shows the function call.

    DATE_FORMAT(created_at, '%Y-%m-%d')
  2. Build a short date

    Use %d for the 2-digit day, %b for the short month name and %Y for the year, which prints 04 Mar 2026.

    SELECT DATE_FORMAT(created_at, '%d %b %Y') FROM orders;
  3. Watch the minutes

    In MySQL %M is the month name, and minutes are %i. The SQL datetime format is %Y-%m-%d %H:%i:%s.

  4. 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.

Try it now

Common mistakes

Using %M for minutes
This prints March where you expected 07. Use %i.
Expecting time zone codes
DATE_FORMAT has no code for the UTC offset. Convert with CONVERT_TZ and 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:

Tutorial · 5 min · beginner

How to format dates in Python with strftime

Use the strftime cheat sheet to build Python date formats for ISO 8601, day-first dates, month names and 12-hour times, with examples for each code.