TIMESTAMPDIFF and TIMESTAMPADD functions in MySQL _ MySQL

Source: Internet
Author: User
Usage of TIMESTAMPDIFF and TIMESTAMPADD functions in MySQL bitsCN.com
In MySQL, the TIMESTAMPDIFF and TIMESTAMPADD functions are often used in applications. 1. TIMESTAMPDIFF syntax: TIMESTAMPDIFF (interval, datetime_expr1, datetime_expr2 ). Returns the integer difference between datetime_expr1 and datetime_expr2the. 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) [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 ') | + limit + | 8820 | + limit + 1 row in set (0.01 sec) II. TIMESTAMPADD syntax: TIMESTAMPADD (interval, int_expr, datetime_expr) description: add the integer expression int_expr 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) bitsCN.com

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.