Calculate Date Differences in MySQL

This content 6 years old. Please, read this page keeping its age in mind along with the fact technology changes fast and the information on this page me be outdated, not best practice, or plain wrong.

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)

Speak Your Mind

*

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