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?