Time mysql database string conversion

1 , the current date, time 

now () to get the current date and time // 2019 - 11 - 12  18 : 18 : 57 
CURDATE () the current date, /// 2019 - 11 - 12 
curtime () the current time // 18 : 18 : 57 is 
CURRENT_TIME (); // with curtime (), CURRENT_TIME 
CURRENT_DATE (); // with CURDATE (), CURRENT_DATE 
CURRENT_TIMESTAMP () // with now () 

2 , the time taken: 

DATE (expr) //If the resolution fails to return Null, return date type DATE 

Time (expr) // return time type Time 

year (expr) // Returns the 

month The (expr) // Returns [ 1 - 12 ] 

Day (expr) // Returns [ . 1 - 31 is ] 

hour (expr) // returns the number [ 0 - 23 is ] 

minute (expr) // returns the number [ 0 - 59 ] 

LAST_DAY (date) // return the last day, the date type return // 2018 - 04 - 30 

to_days (expr)// return 0 to January 1 of the year the total number of days in 

the DATE_FORMAT (expr, pattern) // time interception returns the string 
expr: time string, date string or date time type. 
For the interception of the year, month, day, hour, minute, second string is returned correspondence, because the date and time type mysql itself provides only DATE, Time, datetime , timestamp , year five types 

3 , by date and time Save 

ADDDATE (date, iNTERVAL expr unit) returns the date format 

date time date to be operated, the date may be the date string type 
iNTERVAL: MySQL keyword, meaning the interval, gap 
means operating unit, year, month, day , hours, minutes, seconds corresponds YEAR, MONTH , DAY , HOUR, MINUTE, sECOND, 
expr want to increase or decrease the time unit. expr > 0 , increases, expr < 0 reduction 

SUBDATE (date, INTERVAL expr unit) similar ADDDATE () 

. 4 the difference between the two dates 

DATEDIFF(date1, DATE2)   // difference between the two dates 

5 , the date string is converted to 

the DATE_FORMAT (DATE, ' % Y-M-% D%% H:% I:% S ' ) // Switch characters string 
TIME_FORMAT (dATE, pattern) // only conversion time, conversion date not 
FROM_UNIXTIME ( timestamp , pattern) // time stamp to a string 

6 , the string transfer time 
STR_TO_DATE (dateStr, pattern) 

dateStr: string date expression 
pattern: pattern matching 

7 , the time stamp conversion 

UNIX_TIMESTAMP ( [ dATE ] ) into the date stamp, the default parameters can not write now () 
dATE datetime type may be time string may be ' 2018 - 2 - 12 is '

FROM_UNIXTIME ( timestamp , ' % Y-M-% D%% H:% I:% S ' ) formatted according to the format timestamp 

timestamp : timestamp i.e. UNIX_TIMESTAMP () 
mode pattern of the target string. Results returned when using the format parameter *** string *** . Typical times more formatting parameters as placeholders refer to,
 % the Y years, four digits
 % Y years, the last two digits
 % m month, numbers [ 1-12 ] 
% D day, day of the month in the , two numbers [ 1-31 ] 
% H hours, 24 ary [ 0-23 ] 
% H hours, 12 ary [ 0-11 ] 
% I min [ 0-59 ] 
% S|  % S second 0 - 59

 

Guess you like

Origin www.cnblogs.com/xiaoxiao075/p/11949668.html
Recommended