Mysql common time functions

Source: Internet
Author: User
Tags add time


Several commonly used time functions in mysql check the api documentation each time they write SQL statements about the time. In large space, they can be found in just half a day, to improve efficiency, take the lead in recording several commonly used time SQL functions as follows: www.2cto.com 1. function used to evaluate the time difference: Java code TIMESTAMPDIFF (interval, int_expr, datetime_expr) returns the integer difference between the datetime or datetime expression datetime_expr1 and datetime_expr2. The unit of the result is given by the interval parameter.
The value of interval must be one of the Java code FRAC_SECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, or YEAR. For example: Java code mysql> select timestampdiff (MONTH, '2017-02-01 ', '2017-05-01'); www.2cto.com-> 3
2. Add 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 value is the same as the preceding one. For example: Java code mysql> select timestampadd (MINUTE, 1, '2017-01-02 ');-> '2017-01-02 00:01:00' mysql> select timestampadd (WEEK, 1, '2017-01-02 ');-> '2017-01-09' By gwh_08

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.