Skip to content

PERIOD_DIFF

  • 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.
SELECT PERIOD_DIFF(202012,201911) as Months_Difference;
+-------------------+
| Months_Difference |
+-------------------+
| 13 |
+-------------------+

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.