This tutorial explains how to use the MySQL PERIOD_DIFF function with syntax and examples.
The MySQL PERIOD_DIFF function returns the difference in months between two periods (formatted as YYMM or YYYYMM).
The syntax for the PERIOD_DIFF function in MySQL is:
PERIOD_DIFF( period1, period2 )
A period formatted as either YYMM or YYYYMM.
A period formatted as either YYMM or YYYYMM.
The PERIOD_DIFF function can be used in the following versions of MySQL:
Let's look at some MySQL PERIOD_DIFF function examples and explore how to use the PERIOD_DIFF function in MySQL.
For example:
mysql> SELECT PERIOD_DIFF(201405,201402);
Output: 3
mysql> SELECT PERIOD_DIFF(201508,201408);
Output: 12
mysql> SELECT PERIOD_DIFF(201408,201508);
Output: -12
mysql> SELECT PERIOD_DIFF(1405,1402);
Output: 3
mysql> SELECT PERIOD_DIFF(201411,1409);
Output: 2
mysql> SELECT PERIOD_DIFF(1412,201405);
Output: 7