Arrangement of several commonly used time functions in mysql
This article mainly introduces "several commonly used time functions of mysql". In daily operation, I believe that many people have doubts about several commonly used time functions of mysql. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "several commonly used time functions of mysql". Next, please follow the editor to study!
Several commonly used time functions
Every time you write a sql about time, you have to check the api document and find it for a long time in a large space. In order to improve efficiency, record several common time sql functions as follows:
1. The function of finding the time difference:
Java code
TIMESTAMPDIFF (interval,int_expr,datetime_expr)
Returns the integer difference between the date or date-time expressions datetime_expr1 and datetime_expr2 the.
The unit of the result is given by the interval parameter.
The legal value of interval:
Java code
FRAC_SECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER or YEAR
It has to be one of them.
Such as:
Java code
Mysql > SELECT TIMESTAMPDIFF (MONTH,'2003-02-01)
Www.2cto.com
-> 3
two。 Increase time:
Java code
TIMESTAMPADD (interval,int_expr,datetime_expr)
Add the integer expression int_expr to the date or date-time expression datetime_expr.
The unit of int_expr is given by the interval parameter.
The parameter values are the same as above.
Such as:
Java code
Mysql > SELECT TIMESTAMPADD (MINUTE,1,'2003-01-02')
-> '2003-01-02 00 purl 01purl'
Mysql > SELECT TIMESTAMPADD (WEEK,1,'2003-01-02')
-> '2003-01-09'
At this point, the study of "several commonly used time functions of mysql" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!