MySQL date format DD/MM/YYYY select query?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
In MySQL, a DATE value is stored as a real date, not as a formatted string such as DD/MM/YYYY. If you want 25/12/2026 in query output, the correct tool is DATE_FORMAT for display or STR_TO_DATE when parsing user input into a proper date.
Format a Date in a SELECT
Use DATE_FORMAT when the column already contains a valid DATE or DATETIME.
The format string means:
- '
%dfor day with leading zero' - '
%mfor month with leading zero' - '
%Yfor four-digit year'
This affects only the result set. The underlying column remains a real date value, which is what you want for sorting, filtering, and indexing.
Parse DD/MM/YYYY Input into a Date
If input arrives as a string such as 11/03/2026, convert it into a proper DATE with STR_TO_DATE.
That conversion should happen at ingestion time whenever possible. Storing raw formatted date strings is a design mistake because string dates are harder to validate and query.
Filtering and Sorting Correctly
A common mistake is to format the date too early and then try to sort or filter the formatted string. Format only for presentation. Keep comparisons on the native date column.
Correct:
Risky and slower:
The second version applies a function to the column, which can prevent effective index use and turns a date comparison into string logic.
DATETIME Columns Work Too
If the column includes time, you can still format only the date portion or include time in the output.
That is useful for reports and exports, but the same rule applies: store native temporal data, then format in the query or application layer when needed.
Prefer Formatting at the Presentation Layer When Possible
Although MySQL can format output, many applications choose to return the raw date and format it in the API, template, or client code. That makes localization and display customization easier. Database formatting is most useful for ad hoc reports, exports, or SQL-only workflows.
If the same query feeds multiple consumers, returning the raw date may be the cleaner contract.
Common Pitfalls
- Expecting MySQL to store
DATEvalues inDD/MM/YYYYformat confuses storage with display. The database stores a real date, not a formatted string. - Storing dates as
VARCHARbecause the input arrives asDD/MM/YYYYmakes querying and validation harder. Convert toDATEwhen inserting. - Filtering on
DATE_FORMAT(column, ...)instead of the raw date column can hurt performance and index usage. Compare native dates directly. - Mixing up
%mand%iproduces incorrect output because%mis month and%iis minutes. Check the format tokens carefully. - Assuming formatted strings sort like dates is unsafe. Sort by the real date column, not the display string.
Summary
- Use
DATE_FORMAT(date_col, '%d/%m/%Y')to display a MySQL date asDD/MM/YYYY. - Use
STR_TO_DATEto parse incoming strings into proper date values. - Keep dates stored as native
DATEorDATETIMEcolumns. - Filter and sort on the raw date column, then format only for output.
- Treat formatting as presentation logic, not as the storage model.

