Home > Database > Mysql Tutorial > body text

How to use the DATE_FORMAT function in MySQL

WBOY
Release: 2023-05-27 11:24:23
forward
2787 people have browsed it

DATE_FORMAT(date, format): Format date according to parameters.

SELECT DATE_FORMAT(‘2016-01-16 22:23:00','%W %M %Y') 
SELECT DATE_FORMAT(‘2016-01-16 22:23:00','%D %y %a %d %m %b %j') 
SELECT DATE_FORMAT(‘2016-01-16 22:23:00','%H %k %I %r %T %S %w') 
SELECT DATE_FORMAT(‘2016-01-16 22:23:00','%Y-%m-%d %H:%i:%s')
Copy after login
-> Saturday January 2016
-> 16th 16 Sat 16 01 Jan 016
-> 22 22 10 10:23:00 PM 22:23:00 00 6
-> 2016-01-16 22:23:00
Copy after login

Format formats are listed:

%M Month name (January...December)
%W Week name (Sunday...Saturday)
% D The day of the month with an English prefix (1st, 2nd, 3rd, etc.)
%Y year, number, 4 digits
%y year, number, 2 digits
%a Abbreviated day of the week name (Sun...Sat)
%d Number of days in the month, number (00...31)
%e Number of days in the month, number (0...31)
%m Month, number (01 ……12)
%c Month, number (1……12)
%b Abbreviated month name (Jan……Dec)
%j Number of days in a year (001……366)
%H hours(00……23)
%k hours(0……23)
%h hours(01……12)
%I hours(01……12)
%l hour (1...12)
%i minute, number (00...59)
%r time, 12 hours (hh:mm:ss [AP]M)
%T time, 24 hours (hh:mm:ss)
%S seconds (00...59)
%s seconds (00...59)
%p AM or PM
%w In a week Number of days (0=Sunday...6=Saturday)
%U Week (0...52), here Sunday is the first day of the week
%u Week (0...52), here Monday is the day of the week The first day
%% characters % )

TIME_FORMAT(time,format):
The specific usage is similar to DATE_FORMAT(), but TIME_FORMAT only handles hours , minutes and seconds (the remaining symbols produce a NULL value or 0)

The above is the detailed content of How to use the DATE_FORMAT function in MySQL. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!