Reprinted: http://www.w3school.com.cn/sql/sql_isnull.asp
Time function
1、NOW
Function to get the current date and time.
Syntax: NOW ()
For example: select NOW ();
2 、 CURDATE
Get current date
Syntax: CURDATE ()
3 、 CURTIME ()
Get current time
Syntax: CURTIME ()
4、DATE
Get date time or date part of date
Syntax: DATE (date)
The date parameter is a legal date expression.
5、EXTRACT
Get individual parts of the returned date / time, such as year, month, day, hour, minute, etc.
Syntax: EXTRACT (unit FROM date)
The date parameter is a legal date expression.
unit 参数可以是下列的值:MICROSECOND、SECOND、MINUTE、HOUR、DAY、WEEK、MONTH、QUARTER、YEAR、SECOND_MICROSECOND、MINUTE_MICROSECOND、MINUTE_SECOND、HOUR_MICROSECOND、HOUR_SECOND、HOUR_MINUTE、DAY_MICROSECOND、DAY_SECOND、DAY_MINUTE、DAY_HOUR、YEAR_MONTH
For example, get the current year and month: select EXTRACT (YEAR_MONTH FROM now ());
6、DATE_ADD
Add the date to the specified time interval.
语法:DATE_ADD(date,INTERVAL expr type)
The date parameter is a legal date expression. The expr parameter is the added time interval.
type 参数可以是下列值:MICROSECOND、SECOND、MINUTE、HOUR、DAY、WEEK、MONTH、QUARTER、YEAR、SECOND_MICROSECOND、MINUTE_MICROSECOND、MINUTE_SECOND、HOUR_MICROSECOND、HOUR_SECOND、HOUR_MINUTE、DAY_MICROSECOND、DAY_SECOND、DAY_MINUTE、DAY_HOUR、YEAR_MONTH
For example: select DATE_ADD (now (), INTERVAL 2 DAY); // Get the time after two days
7 DATE_SUB
Subtract the date from the specified time interval.
语法:DATE_SUB(date,INTERVAL expr type)
The date parameter is a legal date expression. The expr parameter is the added time interval.
type 参数可以是下列值:MICROSECOND、SECOND、MINUTE、HOUR、DAY、WEEK、MONTH、QUARTER、YEAR、SECOND_MICROSECOND、MINUTE_MICROSECOND、MINUTE_SECOND、HOUR_MICROSECOND、HOUR_SECOND、HOUR_MINUTE、DAY_MICROSECOND、DAY_SECOND、DAY_MINUTE、DAY_HOUR、YEAR_MONTH
For example: select DATE_SUB (now (), INTERVAL 2 DAY); // Get the time two days ago
8、DATEDIFF
Get the number of days between two dates. (Only the date part is involved in the calculation)
Syntax: DATEDIFF (date1, date2)
The date1 and date2 parameters are legal dates or date / time expressions.
For example: SELECT DATEDIFF (NOW (), '2008-08-08') AS Beijing Olympic Games many days ago;
9、DATEFORMAT
Format date and time
Syntax: DATE_FORMAT (date, format)
The date parameter is a legal date. format specifies the date / time output format.
Format: description
% a: Abbreviated weekday name
% b: Abbreviated month name
% c: month, value
% D: Day of the month with English prefix
% d: day of the month, value (00-31)
% e: day of the month, value (0-31)
% f: microseconds
% H: hour (00-23)
% h: hour (01-12)
% I: hour (01-12)
% i: minute, value (00-59)
% j: day of the year (001-366)
% k: hour (0-23)
% l: hour (1-12)
% M: month name
% m: month, value (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: day of the week
% 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
% Y: year, 4 digits
% y: year, 2 digits