Calculate Date Differences in MySQL

There is a function in MySQL that will calculate the number of days between two given dates:  datediff

Example

mysql> select datediff('2014-06-09','2014-07-07');
+----------------------------------------------+
| datediff('2014-06-09','2014-07-07') |
+----------------------------------------------+
| -28 |
+----------------------------------------------+
1 row in set (0.00 sec)

Calculate Days Between Now and Specific Date

mysql> select datediff(now(),'2014-07-01');
+------------------------------+
| datediff(now(),'2014-07-01') |
+------------------------------+
|                            6 |
+------------------------------+
1 row in set (0.00 sec)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.