Name
PERIOD_ADD()
Synopsis
PERIOD_ADD(yearmonth
,number
)
This function adds a specified number of months to a period,
which is a string containing only the year and month in either
yyyymm
or yymm
format. Here is an example:
SELECT CURDATE( ), EXTRACT(YEAR_MONTH FROM CURDATE( )) AS 'Current Period', PERIOD_ADD(EXTRACT(YEAR_MONTH FROM CURDATE( )), 1) AS 'Next Accounting Period'; +------------+----------------+------------------------+ | CURDATE( ) | Current Period | Next Accounting Period | +------------+----------------+------------------------+ | 2008-12-15 | 200812 | 200901 | +------------+----------------+------------------------+
Functions such as this one are particularly useful when you are building a program and need to design an SQL statement that will account for accounting periods that roll into the following year.
Get MySQL in a Nutshell, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.