MySQL DATE_FORMAT Builder
Compose a MySQL DATE_FORMAT() format string by clicking specifiers or typing it, and see the formatted output instantly for a sample datetime. Every specifier from the MySQL 8.0 manual is implemented with the server's exact semantics — %D ordinals, unpadded %c/%e/%k/%l, %f microseconds, %j day of year, and the four week specifiers %U/%u/%V/%v with their %X/%x years using MySQL's own WEEK() algorithm. The tool writes ready-to-run DATE_FORMAT and STR_TO_DATE statements, shows the PostgreSQL to_char and SQL Server FORMAT() equivalents, and converts strftime or to_char patterns into MySQL format. Runs entirely in your browser.
Convert an existing pattern to MySQL
%Y-%m-%d %H:%i:%SParts shown as [?…] could not be converted exactly and must be handled with a separate function. Remember: strftime %M (minutes) becomes MySQL %i, and strftime %S/%s differ — MySQL %s is seconds, not the Unix epoch.
Do more than mysql date_format builder — meet Chat2DB
Chat2DB is an AI-powered SQL client for Windows, macOS and Linux. Write SQL in natural language, format and optimize queries automatically, and manage MySQL, PostgreSQL, Oracle and 20+ other databases in one workspace.
How to use
- Pick a preset or type a format string; click the specifier buttons (%Y, %M, %D, %i, %v …) to append them and watch the preview update.
- Enter a sample datetime (YYYY-MM-DD HH:MM:SS.ffffff) or press Now, and optionally your table and column names.
- Copy the generated DATE_FORMAT / STR_TO_DATE SQL or the PostgreSQL and SQL Server equivalents; use the converter below to translate an existing strftime or to_char pattern.
Frequently asked questions
What is the difference between %i, %M and %m in MySQL DATE_FORMAT?
In MySQL, %i is minutes (00-59), %m is the month number (01-12) and %M is the full month name (January). This differs from strftime, PHP, Python and the Unix date command, where %M means minutes — copying '%Y-%m-%d %H:%M:%S' into MySQL prints the month name instead of minutes. Use '%Y-%m-%d %H:%i:%s' (or %T for the time part). Likewise %s is seconds in MySQL, not the Unix epoch.
Which week specifier should I use: %U, %u, %V or %v?
%U (Sunday first) and %u (Monday first) return 00-53 and put days before the first week into week 00; they match WEEK(date, 0) and WEEK(date, 1). %V and %v return 01-53 and roll early-January days into the last week of the previous year, so they must be paired with %X and %x respectively. For ISO 8601 weeks use '%x-W%v' — e.g. 2021-01-03 is week 2020-53. Using %Y with %v gives wrong labels around New Year.
Should I store dates as formatted strings in MySQL?
No — store them in DATE, DATETIME or TIMESTAMP columns and format only when displaying. String dates cannot use date indexes or range scans, sort incorrectly ('03/01/2026' sorts before '12/31/2025'), and need STR_TO_DATE for every calculation. Wrapping an indexed column in DATE_FORMAT inside WHERE also prevents index use, so filter with ranges instead. Chat2DB, a free AI-powered SQL client, displays datetime columns properly and lets you test DATE_FORMAT expressions interactively: download it at https://chat2db.ai/download or use the web version at https://app.chat2db.ai.
