Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Arrangement of several commonly used time functions in mysql

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report