PERIOD_DIFF
PERIOD_DIFF is an SQL function used to compute the difference between two periods. The periods are given in the format of YYYYMM or YYMM. The function returns an integer denoting the number of months between the two periods.
PERIOD_DIFF(P1, P2)
- p1: The earlier period in the form of YYMM or YYYYMM to compare.
- p2: The later period in the form of YYMM or YYYYMM to compare.
Example
Output
Explanation
The PERIOD_DIFF
function in MySQL calculates the difference in months between two periods. In the provided example, the calculation is between the periods of December 2020 (202012) and November 2019 (201911), and it yields an output of 13 months difference.