PERIOD_DIFF
PERIOD_DIFF(P1, P2)
Section titled “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
Section titled “Example”SELECT PERIOD_DIFF(202012,201911) as Months_Difference;Output
Section titled “Output”+-------------------+| Months_Difference |+-------------------+| 13 |+-------------------+Explanation
Section titled “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.