MySQL PERIOD_DIFF

MySQL PERIOD_DIFF is one of the Date Functions, which returns the total number of months between Periods 1 and 2. It accepts the arguments in YYYYMM, or YYMM formats only. The basic syntax of the PERIOD_DIFF Function is as shown below:

PERIOD_DIFF(Period1, Period2);

MySQL PERIOD_DIFF Example

This Period difference accepts either the YYMM or YYYYMM format value as an argument value. Also, read about the MySQL PERIOD_ADD function.

The following Date method examples help you understand the use of this MySQL function. In this example, we are finding the total number of months between different dates.

SELECT PERIOD_DIFF(201608, 201602);

SELECT PERIOD_DIFF(201608, 201209);

SELECT PERIOD_DIFF(7508, 7609);
PERIOD_DIFF Function Example

TIP: Please refer to the MySQL DATEDIFF and MySQL TIMESTAMPDIFF functions from the list of available MySQL Date functions.