PERIOD_ADD( )

This MySQL 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.

Syntax

Below is the syntax for this command. Text within square brackets (i.e, [ and ] ) are optional. Choices are separated by bars (i.e, | ). Ellipses preceded by a comma indicates a repeating pattern. Ellipses before or after syntax are used to highlight a relevant except from the larger syntax. Text displayed in italic letters represent text that should be replaced with the specific names related to the database (e.g., column with the name of the column).

PERIOD_ADD(yearmonth, number)

Explanation

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.

Examples

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're building a program and you need to design an SQL statement that will account for accounting periods that roll into the following year.