DATEDIFF(expr1,expr2): returns expr1 - expr2 as a value in days : DATEDIFF « Date Time Functions « MySQL Tutorial






Only the date parts of the values are used in the calculation.

mysql>
mysql> SELECT DATEDIFF('1997-12-31 23:59:59','1997-12-30');
+----------------------------------------------+
| DATEDIFF('1997-12-31 23:59:59','1997-12-30') |
+----------------------------------------------+
|                                            1 |
+----------------------------------------------+
1 row in set (0.00 sec)

mysql>
mysql> SELECT DATEDIFF('1997-11-30 23:59:59','1997-12-31');
+----------------------------------------------+
| DATEDIFF('1997-11-30 23:59:59','1997-12-31') |
+----------------------------------------------+
|                                          -31 |
+----------------------------------------------+
1 row in set (0.00 sec)

mysql>








14.9.DATEDIFF
14.9.1.DATEDIFF(expr1,expr2): returns expr1 - expr2 as a value in days
14.9.2.Using DATEDIFF with data in a column