Collections:
PERIOD_DIFF() - Difference of Year-Month Periods
How to calculate the difference between two year-month periods using the PERIOD_DIFF() function?
✍: FYIcenter.com
PERIOD_DIFF(P1, P2) is a MySQL built-in function that
calculates the difference between two year-month periods.
For example:
SELECT PERIOD_DIFF(201802, 201703), PERIOD_DIFF(201703, 201802); -- +-----------------------------+-----------------------------+ -- | PERIOD_DIFF(201802, 201703) | PERIOD_DIFF(201703, 201802) | -- +-----------------------------+-----------------------------+ -- | 11 | -11 | -- +-----------------------------+-----------------------------+
Reference information of the PERIOD_DIFF() function:
PERIOD_DIFF(P1, P2): int Returns the number of months between periods P1 and P2. P1 and P2 should be in the format YYMM or YYYYMM. Arguments, return value and availability: P1: Required. The year-month period to be subtracted from. P2: Required. The year-month period to be subtracted. int: Return value. The difference in months. Available since MySQL 4.
Related MySQL functions:
⇐ PERIOD_ADD() - Adding Months to Period
2023-11-17, 1044🔥, 0💬
Popular Posts:
Can Date and Time Values Be Converted into Integers in SQL Server Transact-SQL? Can date and time va...
Where to find SQL Server Transact-SQL language references? You can find SQL Server Transact-SQL lang...
How To Divide Query Output into Multiple Groups with the GROUP BY Clause in SQL Server? Sometimes, y...
How To Use "IF ... ELSE IF ..." Statement Structures in SQL Server Transact-SQL? "IF ... ELSE IF ......
What Are Out-of-Range Errors with DATETIME values in SQL Server Transact-SQL? When you enter DATETIM...