The use of Timestampdiff and Timestampadd functions in MySQL

Source: Internet
Author: User

Timestampdiff

Grammar:

Timestampdiff (INTERVAL,DATETIME_EXPR1,DATETIME_EXPR2).

Description

Returns an integer difference between a date or datetime expression Datetime_expr1 and datetime_expr2the. The unit of the result is given by the interval parameter. The parameter must be one of the following values:

    • Frac_second---(indicates the interval is milliseconds)
    • SECOND---(sec)
    • MINUTE---(minutes)
    • HOUR---(hours)
    • Day---(days)
    • WEEK---(week)
    • Month---(months)
    • QUARTER---(quarterly)
    • Year---(years)
Use the following:
Mysql> SelectTimestampdiff ( Day,'2012-08-24','2012-08-30'); +----------------------------------------------+  |Timestampdiff ( Day,'2012-08-24','2012-08-30')|  +----------------------------------------------+  |                                            6 |   +----------------------------------------------+  1Rowinch Set(0.00Sec

Mysql> SelectTimestampdiff (MINUTE,'2012-08-24 09:00:00','2012-08-30 12:00:00'); +-------------------------------------------------------------------+  |Timestampdiff (MINUTE,'2012-08-24 09:00:00','2012-08-30 12:00:00')|  +-------------------------------------------------------------------+  |                                                              8820 |   +-------------------------------------------------------------------+  1Rowinch Set(0.01Sec

Timestampadd

Syntax: Timestampadd (interval,int_expr,datetime_expr) Description: Adds an integral expression int_expr to a date or datetime expression datetime_expr. The interval in the formula are the same as the values listed above.
Mysql> SelectTimestampadd (MINUTE,8820,'2012-08-24 09:00:00'); +-------------------------------------------------+  |Timestampadd (MINUTE,8820,'2012-08-24 09:00:00')|  +-------------------------------------------------+  |  -- ,- -  A:xx:xx                             |   +-------------------------------------------------+  1Rowinch Set(0.00Sec

From: http://blog.csdn.net/zmxiangde_88/article/details/8011661

The use of Timestampdiff and Timestampadd functions in MySQL

Related Article

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.