The DATE_FORMAT() function is used to display date/time data in different formats.
The format of the format parameter is
%a | Abbreviated week name |
%b | Abbreviated month name |
%c | month, value |
%D | day of the month with an English prefix |
%d | Day of the month, numeric (00-31) |
%e | day of the month, numeric (0-31) |
%f | microseconds |
%H | Hours (00-23) |
%h | Hours (01-12) |
%I | Hours (01-12) |
%i | minutes, numeric (00-59) |
%j | Day of the Year (001-366) |
%k | Hours (0-23) |
%l | Hours (1-12) |
%M | month name |
%m | month, numeric (00-12) |
%p | AM or PM |
%r | Time, 12-hour (hh:mm:ss AM or PM) |
%S | Seconds (00-59) |
%s | Seconds (00-59) |
%T | time, 24-hour (hh:mm:ss) |
% U | Week (00-53) Sunday is the first day of the week |
% u | Week (00-53) Monday is the first day of the week |
%V | Week (01-53) Sunday is the first day of the week, used with %X |
%v | Week (01-53) Monday is the first day of the week, used with %x |
%W | week name |
%w | day of the week (0=Sunday, 6=Saturday) |
%X | Year, where Sunday is the first day of the week, 4 digits, used with %V |
%x | Year, where Monday is the first day of the week, 4 digits, used with %v |
%AND | year, 4 digits |
%and | year, 2 digits |
example:
Output result:
2. MySQL format function FROM_UNIXTIME()