DATE_FORMAT()
This page is part of MariaDB's Documentation.
The parent of this page is: Functions for MariaDB Xpand
Topics on this page:
Overview
Returns a date value as a string using the given format.
USAGE
DATE_FORMAT(date, format)
Argument Name | Description |
---|---|
| The date to format |
| The format to apply |
DETAILS
DATE_FORMAT()
is a date-time function that returns a date as a string using the given format.
A NULL
is returned if any argument is NULL
.
The format string can contain any arbitrary text with the following formatting characters being replaced by date and time information:
Option | Description |
---|---|
| Abbreviated weekday name in the current locale |
| Abbreviated month name in the current locale |
| Month number in 1 or 2 digits |
| Day number with English suffix "st", "nd", "rd", or "th" |
| Day number in 2 digits |
| Day number in 1 or 2 digits |
| Microseconds (6 digits) |
| Hour in 2 digits (00-23) |
| Hour in 2 digits (01-12) |
| Hour in 2 digits (01-12) |
| Minute in 2 digits |
| Numeric day of the year in 3 digits (001-366) |
| Hour in 1 to 2 digits (0-23) |
| Hour in 1 to 2 digits (1-12) |
| Full month name in the current locale |
| Month number in 2 digits |
| AM or PM according to the current locale |
| An alias for |
| Seconds in 2 digits |
| Seconds in 2 digits |
| An alias for "%H:%i:%S" |
| Week number (00-53) starting on Sunday |
| Week number (00-53) starting on Monday |
| Week number (01-53) starting on Sunday |
| Week number (01-53) starting on Monday |
| Full weekday name in current locale |
| Day of the week (Sunday is 0) |
| Year with 4 digits according to |
| Year with 4 digits according to |
| Year with 4 digits |
| Year with 2 digits |
| A literal |
EXAMPLES
SELECT DATE_FORMAT('2020-01-01 01:23:00', '%W %D %M %Y');
+---------------------------------------------------+
| DATE_FORMAT('2020-01-01 01:23:00', '%W %D %M %Y') |
+---------------------------------------------------+
| Wednesday 1st January 2020 |
+---------------------------------------------------+
SELECT DATE_FORMAT('2020-01-01 01:23:00', '%H:%i:%s')
+------------------------------------------------+
| DATE_FORMAT('2020-01-01 01:23:00', '%H:%i:%s') |
+------------------------------------------------+
| 01:23:00 |
+------------------------------------------------+