Description: Returns a date (a DATE or DATETIME type), in a format specified by format as shown in Table C.2.
Parameter Within Format | Output Format | Example |
---|---|---|
%a | Weekday name, abbreviated | Sun, Mon |
%b | Month name, abbreviated | Jan |
%c | Month without leading 0 | 1, 2...12 |
%D | Day of month, suffixed | 1st, 2nd |
%d | Day of month with leading 0 | 01, 02 |
%e | Day of month without leading 0 | 1, 2 |
%h or %I | Hour with leading 0 (12h) | 01, 02…12 |
%H | Hour with leading 0 (24h) | 00, 01…23 |
%i | Minutes | 00, 01…59 |
%j | Day of year with leading 0's | 001, 002…366 |
%k | Hour without leading 0 (24h) | 0, 1…23 |
%l | Hour without leading 0 (12h) | 1, 2…12 |
%M | Month name | January |
%m | Month with leading 0 | 01 |
%P | AM or PM | AM, PM |
%r | 12-hour time | 10:30:21 PM |
%S or %s | Seconds | 00, 01...59 |
%T | 24-hour time | 22:30:21 |
%U | Week number in the year[*] | 01, 02...52 |
%u | Week number in the year[**] | 01, 02...52 |
%X and %V | Year and week number[*] | 2001 52 |
%x and %v | Year and week number[**] | 2001 52 |
%W | Weekday name | Sunday, Monday |
%w | Weekday number[*] | 0, 1…6 |
%y | Numeric year, 2-digit | 02 |
%Y | Numeric year, 4-digit | 2002 |
%% | Literal % symbol | % |
[*] in which Sunday is the first day of the week (day 0)
[**] in which Monday is the first day of the week
Examples:
DATE_FORMAT('2002-01-05','%W %D %M %Y') returns Saturday 5th January 2002.
DATE_FORMAT('2002-01-05 16:20:00','%D %M %Y at %r') returns 5th January 2002 at 04:20:00 PM.
See also: TIME_FORMAT()
18.189.188.238