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, 1151🔥, 0💬
Popular Posts:
How To Format Time Zone in +/-hh:mm Format in SQL Server Transact-SQL? From the previous tutorial, y...
How To Use GO Command in "sqlcmd" in SQL Server? "sqlcmd" is a command line client application to ru...
Where to find answers to frequently asked questions on Downloading and Installing SQL Server 2005 Ex...
How To Break Query Output into Pages in MySQL? If you have a query that returns hundreds of rows, an...
How to set database to be READ_ONLY in SQL Server? Databases in SQL Server have two update options: ...