Home »
MySQL »
MySQL date/time Functions
MySQL PERIOD_DIFF() Function
MySQL | PERIOD_DIFF() Function: Learn about the PERIOD_DIFF() function, how it works, its usages, syntax, and examples.
Submitted by Apurva Mathur, on October 11, 2022
PERIOD_DIFF() Function
When you want to get the difference between two periods than in such case, we use this PERIOD_DIFF() function.
PERIOD_DIFF() Syntax
SELECT PERIOD_DIFF(period1, period2);
PERIOD_DIFF() Parameter(s)
This function takes two periods of dates which should have YYMM or YYYYMM as their format.
PERIOD_DIFF() Return Value
This function will return the number after taking out the difference between the two periods.
MySQL PERIOD_DIFF() Function Example 1
SELECT PERIOD_DIFF(202207,202204);
In this example the YYYYMM format is used.
MySQL PERIOD_DIFF() Function Example 2
SELECT PERIOD_DIFF(0207,0102);