DATE_FORMAT() converts a DATETIME or DATE column into a readable string according to a supplied format mask.
DATE_FORMAT() converts a DATE or DATETIME value into a string based on a format mask—similar to strftime in C. It is the go-to MariaDB function for presenting dates in reports, exports, and UI layers.
The basic form is DATE_FORMAT(date_expression, format_mask).The first argument is any date/time expression; the second is a string containing format specifiers like %Y (4-digit year) or %d (zero-padded day).
Common tokens include %Y = 2024, %y = 24, %m = 03, %d = 09, %H = 14, %i = 05, and %p = AM/PM. Combine them to build human-friendly strings.
Use DATE_FORMAT(Orders.order_date,'%M %d, %Y') to get "March 09, 2024".Join this with customer data for mailing labels or PDFs.
MariaDB inherits the server’s lc_time_names variable. SET it per connection—SET lc_time_names = 'fr_FR'—then DATE_FORMAT(order_date,'%e %M %Y') yields "9 mars 2024".
Switch from %d to %e (day) or from %m to %c (month). "March 9, 2024" reads cleaner than "March 09, 2024".
Keep columns as DATE/DATETIME.Apply DATE_FORMAT() only in SELECTs, views, or presentation layers. This preserves timezone math and indexing.
Filtering with WHERE order_date BETWEEN '2024-01-01' AND '2024-12-31' is Sargable. Avoid wrapping the column in DATE_FORMAT() inside WHERE, which forces full scans.
.
Yes. DATE_FORMAT() accepts any DATE, DATETIME, or TIMESTAMP expression, formatting it without changing timezone data.
Use DATE_FORMAT(order_date,'%Y-%m-%dT%H:%i:%sZ'). The trailing Z is literal; adjust for your timezone if needed.


.avif)
