How many days does MySQL query differ between two dates?

Source: Internet
Author: User
Tags mysql query time and seconds

Requirements Description :

In MySQL, see how many days differ between two dates

Operation Process :

1. Through the DateDiff function, see how many days difference between two dates

Mysql> Select DateDiff('2018-06-26','2018-06-25'),DateDiff('2018-06-20','2018-06-26');+-------------------------------------+-------------------------------------+| DateDiff('2018-06-26','2018-06-25')| DateDiff('2018-06-20','2018-06-26')|+-------------------------------------+-------------------------------------+|                                   1 |                                  -6 |+-------------------------------------+-------------------------------------+1Rowinch Set(0.00Sec

Note: DateDiff (EXPR1,EXPR2), the general return is the difference of EXPR1-EXPR2, the result can be positive, or negative. Mainly two days between dates.

2. Expressions with time and seconds

Mysql> Select DateDiff('2018-06-26 22:00:00 ','2018-06-25'),DateDiff('2018-06-20','2018-06-26 21:00:00 ');+----------------------------------------------+----------------------------------------------+| DateDiff('2018-06-26 22:00:00','2018-06-25')| DateDiff('2018-06-20','2018-06-26 21:00:00')|+----------------------------------------------+----------------------------------------------+|                                            1 |                                           -6 |+----------------------------------------------+----------------------------------------------+1Rowinch Set(0.00Sec

Note: In a date calculation, if there is a minute or two, the part that is ignored is calculated only on the day of the date.

Document creation time: June 26, 2018 12:47:32

Official documentation Reference:

 days from one date to the other. Expr1 and expr2 are date or date-and-time expressions.
Only the date parts of the values is used in the calculation.mysql> SELECT DATEDIFF (' 2007-12-31 23:59:59 ', ' 2007-12-30 ' ); -1mysql> SELECT DATEDIFF (' 2010-11-30 23:59:59 ', ' 2010-12-31 '); -31

How many days does MySQL query differ between two dates?

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.