DATE_FORMAT()
DATE_FORMAT(date
,format
)
Returns the date
value formatted
according to the format
string. Table D-2 shows the specifiers
that can be used in the format
string. Note
that the %
character is required
before each specifier, as shown. This code returns the given date and
time as “Wednesday May 4th 2016 03:02 AM”:
SELECT DATE_FORMAT('2016-05-04 03:02:01', '%W %M %D %Y %h:%i %p');
Specifier | Description |
| Abbreviated weekday name (Sun–Sat) |
| Abbreviated month name (Jan–Dec) |
| Month, numeric (0–12) |
| Day of the month with English suffix (0th, 1st, 2nd, 3rd, ...) |
| Day of the month, numeric (00–31) |
| Day of the month, numeric (0–31) |
| Microseconds (000000–999999) |
| Hour (00–23) |
| Hour (01–12) |
| Hour (01–12) |
| Minutes, numeric (00–59) |
| Day of year (001–366) |
| Hour (0–23) |
| Hour (1–12) |
| Month name (January–December) |
| Month, numeric (00–12) |
| AM or PM |
| Time, 12-hour (hh:mm:ss followed by AM or PM) |
| Seconds (00–59) |
| Seconds (00–59) |
| Time, 24-hour (hh:mm:ss) |
| Week (00–53), where Sunday is the first day of the week |
| Week (00–53), where Monday is the first day of the week |
| Week (01–53), where
Sunday is the first day of the week; used with |
| Week (01–53), where
Monday is the first day of the week; used with |
| Weekday name (Sunday–Saturday) |
| Day of the week (0=Sunday–6=Saturday) |
| Year for the week where
Sunday is the first day of the week, numeric, four digits;
used with |
| Year for the week where
Monday is the first day of the week, numeric, four digits;
used with |
| Year, numeric, four digits |
| Year, numeric, two digits |
| A literal |