Collections:
PERIOD_ADD() - Adding Months to Period
How to add months to a given year-month period using the PERIOD_ADD() function?
✍: FYIcenter.com
PERIOD_ADD(P, N) is a MySQL built-in function that adds months to a given year-month period. For example:
SELECT PERIOD_ADD(202311, 6), PERIOD_ADD(202311, -6); -- +-----------------------+------------------------+ -- | PERIOD_ADD(202311, 6) | PERIOD_ADD(202311, -6) | -- +-----------------------+------------------------+ -- | 202405 | 202305 | -- +-----------------------+------------------------+ SELECT PERIOD_ADD(EXTRACT(YEAR_MONTH FROM NOW()), 6), NOW(); -- +-----------------------------------------------+---------------------+ -- | PERIOD_ADD(EXTRACT(YEAR_MONTH FROM NOW()), 6) | NOW() | -- +-----------------------------------------------+---------------------+ -- | 202405 | 2023-11-15 09:22:11 | -- +-----------------------------------------------+---------------------+
Reference information of the PERIOD_ADD() function:
PERIOD_ADD(P, N): int Adds N months to period P (in the format YYMM or YYYYMM). Returns a value in the format YYYYMM. Arguments, return value and availability: P: Required. The year-month period to add months to. N: Required. The number of months to add. int: Return value. The modified year-month period. Available since MySQL 4.
Related MySQL functions:
⇒ PERIOD_DIFF() - Difference of Year-Month Periods
⇐ NOW() - Start Time of Execution
2023-11-17, 264🔥, 0💬
Popular Posts:
What is dba.FYIcenter.com Website about? dba.FYIcenter.com is a Website for DBAs (database administr...
How To Create a Stored Program Unit in Oracle? If you want to create a stored program unit, you can ...
How To Convert Numeric Expression Data Types using the CAST() Function in SQL Server Transact-SQL? I...
How to download and install the scaled-down database AdventureWorksLT in SQL Server? If you want to ...
How To Provide Default Values to Function Parameters in SQL Server Transact-SQL? If you add a parame...