Usage of TIMESTAMPDIFF and TIMESTAMPADD functions in MySQL

Source: Internet
Author: User


In MySQL, The TIMESTAMPDIFF and TIMESTAMPADD functions are often used in applications. 1. TIMESTAMPDIFF Syntax: TIMESTAMPDIFF (interval, datetime_expr1, datetime_expr2 ). Note: www.2cto.com returns the integer difference between the datetime_expr1 and datetime_expr2the expressions of date and time. The unit of the result is given by the interval parameter. This parameter must be one of the following values: FRAC_SECOND. The interval is millisecond SECOND. Second MINUTE. Minutes HOUR. Hour DAY. Day WEEK. Week MONTH. Month QUARTER. Quarter YEAR. Year
Use the following statement: [SQL] mysql> select TIMESTAMPDIFF (day, '2017-08-24 ', '2017-08-30'); + hour + | TIMESTAMPDIFF (day, '2017-08-24 ', '2017-08-30 ') | + hour + | 6 | + -------------------------------------------- + 1 row in set (2012 sec) www.2cto.com [SQL] mysql> select TIMESTAMPDIFF (MINUTE, '2017-08-24 09:00:00 ', '2017-08-30 12:00:00'); + --- -------------------------------------------------------------- + | TIMESTAMPDIFF (MINUTE, '2017-08-24 09:00:00 ', '2017-08-30 12:00:00 ') | + keys + | 8820 | + keys + 1 row in set (0.01 sec) II. TIMESTAMPADD Syntax: TIMESTAMPADD (interval, int_expr, datetime_expr) www.2cto.com Description: int_ex Add pr to the date or datetime expression datetime_expr. The value of interval is the same as the value listed above.
[SQL] mysql> select TIMESTAMPADD (MINUTE, 8820, '2017-08-24 09:00:00 '); + ----------------------------------------------- + | TIMESTAMPADD (MINUTE, 2012, '2017-08-24 09:00:00 ') | + ------------------------------------------------- + | 2012 12:00:00 | + rows + 1 row in set (0.00 sec)

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.