Detailed description of mysql obtaining the current date function and time formatting parameters, and detailed description of mysql Parameters
MYSQL obtains the current date and Date Format
Get system date: NOW ()
Format date: DATE_FORMAT (date, format)
Note: date: Time Field
Format: Date format
Returns the system date, which is 14:38:59.
Select now ();
Output 09-12-25
Select date_format (now (), '% y-% m-% D ');
Format the date value based on the format string:
% S, % s two-digit second (,..., 59)
% I, % I two-digit score (,..., 59)
% H two-digit hour, 24 hours (,..., 23)
% H two-digit hour, 12 hours (,..., 12)
% K, 24 hours (0, 1,..., 23)
% L hour in numeric format (1, 2,..., 12)
% T 24-hour time format (hh: mm: ss)
% R 12-hour time format (hh: mm: ss AM or hh: mm: ss PM)
% P AM or PM
% W name of each day in a week (Sunday, Monday,..., Saturday)
% A abbreviation of the name of each day in a week (Sun, Mon,..., Sat)
% D indicates the number of days in a month (00, 01,..., 31)
% E indicates the number of days in a month (1, 2,..., 31)
% D indicates the number of days in a month (1st, 2nd, 3rd ,...)
% W represents the number of days in a week (0 = Sunday, 1 = Monday,..., 6 = Saturday)
% J represents the number of days in a year in three digits (001,002,..., 366)
% U Week (0, 1, 52), where Sunday is the first day of the week
% U Week (0, 1, 52), where Monday is the first day of the week
% M month name (January, February,..., December)
% B abbreviated month name (January, February,..., December)
% M double-digit month (01, 02,..., 12)
% C indicates the month (1, 2,..., 12)
The year in the format of % Y.
The year in double-digit % y format.
% Direct value "%"
What is the function for MySQL to get the current time? What is the function for formatting the date?
Use now () to obtain the current time.
Format the time in the database using DATE_FORMA T (date, format ).
Format the date or date and Time Value Based on the format string to return the result string.
You can use DATE_FORMAT () to format the DATE or DATETIME value to obtain the expected format. Format the date value based on the format string:
% S, % s two-digit second (,..., 59)
% I two-digit score (,..., 59)
% H two-digit hour, 24 hours (,..., 23)
% H, % I two-digit hour, 12 hours (,..., 12)
% K, 24 hours (0, 1,..., 23)
% L hour in numeric format (1, 2,..., 12)
% T 24-hour time format (h: m: s)
% R 12-hour time format (hh: mm: ss AM or hh: mm: ss PM)
% P AM or P M
% W name of each day in a week (S u n d a y, Monday,..., Saturday)
% A abbreviation of the name of each day in a week (Sun, Mon,..., Sat)
% D indicates the number of days in a month (00, 01,..., 31)
% E indicates the number of days in a month (1, 2,..., 31)
% D indicates the number of days in a month (1st, 2nd, 3rd ,...)
% W represents the number of days in a week (0 = S u n d a y, 1 = Monday,..., 6 = Saturday)
% J represents the number of days in a year in three digits (001,002,..., 366)
% U Week (0, 1, 52), where Sunday is the first day of the week
% U Week (0, 1, 52), where Monday is the first day of the week
% M month name (J a n u a r y, February,..., December)
% B abbreviated month name (J a n u a r y, February,..., December)
% M double-digit month (01, 02,..., 12)
% C indicates the month (1, 2,..., 12)
The year in the format of % Y.
The year in double-digit % y format.
% Direct value "%"
Select date_format (Date Field, '% Y-% m-% D') as 'date' from test
This is basically the case. It will be a good performance soon ......
Mysql time formatting
DATE_FORMA T (date, format) format the date or date and Time Value Based on the format string, and return the result string.
You can use DATE_FORMAT () to format the DATE or DATETIME value to obtain the expected format. Format the date value based on the format string:
% S, % s two-digit second (,..., 59)
% I two-digit score (,..., 59)
% H two-digit hour, 24 hours (,..., 23)
% H, % I two-digit hour, 12 hours (,..., 12)
% K, 24 hours (0, 1,..., 23)
% L hour in numeric format (1, 2,..., 12)
% T 24-hour time format (h: m: s)
% R 12-hour time format (hh: mm: ss AM or hh: mm: ss PM)
% P AM or P M
% W name of each day in a week (S u n d a y, Monday,..., Saturday)
% A abbreviation of the name of each day in a week (Sun, Mon,..., Sat)
% D indicates the number of days in a month (00, 01,..., 31)
% E indicates the number of days in a month (1, 2,..., 31)
% D indicates the number of days in a month (1st, 2nd, 3rd ,...)
% W represents the number of days in a week (0 = S u n d a y, 1 = Monday,..., 6 = Saturday)
% J represents the number of days in a year in three digits (001,002,..., 366)
% U Week (0, 1, 52), where Sunday is the first day of the week
% U Week (0, 1, 52), where Monday is the first day of the week
% M month name (J a n u a r y, February,..., December)
% B abbreviated month name (J a n u a r y, February,..., December)
% M double-digit month (01, 02,..., 12)
% C indicates the month (1, 2,..., 12)
The year in the format of % Y.
The year in double-digit % y format.
% Direct value "%"
Select date_format (Date Field, '% Y-% m-% D') as 'date' from test