MySQL string to date type selectstr_to_date (2014-08-2000:00:00, % Y-% m-% d % H: % I: % s); 2014-08-2000: 00: 00selectdate_format (1997-10-0422: 23: 00, % H: % I: % s); 22:23:00
MySQL string to date type selectstr_to_date (2014-08-2000:00:00, % Y-% m-% d % H: % I: % s); 2014-08-2000: 00: 00selectdate_format (1997-10-0422: 23: 00, % H: % I: % s); 22:23:00
MySQL string to date type
Select str_to_date ('2017-08-20 00:00:00 ',' % Y-% m-% d % H: % I: % s ');
> 00:00:00
Select date_format ('2017-10-04 22:23:00 ',' % H: % I: % s ');
> 22:23:00
Description
Description
%
Abbreviation of workday (Sun .. Sat)
% B
Abbreviated month name (Jan .. Dec)
% C
Month, digit format (0 .. 12)
% D
Date of the month with English suffix (0th, 1st, 2nd, 3rd ,...)
% D
The date of the month, in the numeric format (00 .. 31)
% E
The date of the month, in the numeric format (0 .. 31)
% F
Microseconds (000000 .. 999999)
% H
Hour (00 .. 23)
% H
Hour (01 .. 12)
% I
Hour (01 .. 12)
% I
Minute, digit format (00 .. 59)
% J
Days in a year (001 .. 366)
% K
Hour (0 .. 23)
% L
Hour (1 .. 12)
% M
Month name (January... December)
% M
Month, digit format (00 .. 12)
% P
AM or PM)
% R
Time, in 12-hour format (hour hh: minute mm: seconds ss plus AM or PM)
% S
Seconds (00 .. 59)
% S
Seconds (00 .. 59)
% T
Time, in 24-hour format (hour hh: minute mm: seconds ss)
% U
Week (00 .. 53), where Sunday is the first day of the week
% U
Week (00 .. 53), where Monday is the first day of the week
% V
Week (01 .. 53), where Sunday is the first day of the week; and % X is used at the same time
% V
Week (01 .. 53), where Monday is the first day of the week; use both % x
% W
Workday name (Sunday... Saturday)
% W
Daily in a week (0 = Sunday .. 6 = Saturday)
% X
The year of the week, in which Sunday is the first day of the week, in the form of a number, 4 digits; and % V at the same time
% X
The year of the week, where Monday is the first day of the week, in the form of a number, 4 digits; used together with % v
% Y
Year, Number Format, 4-digit
% Y
Year, Number Format (2 digits)
%
'%' Text character
All other characters are copied to the result without any explanation.
Note that the '%' character must be before the format specified.
The range of month and date specifiers starts from scratch because MySQL allows storage of incomplete dates such as '2017-00-00.
This article is from the "fuyan" blog. Please keep this source