Name

PERIOD_ADD( )

Synopsis

PERIOD_ADD(yearmonth, value)

This function adds a specified number of months to the year and month given. The date must be in string format and can contain only the year and month in either yyyymm or yymm format. The value for the second argument of the function specifies the number of months to add to the period given.

SELECT PERIOD_ADD(200412, 1)
       AS 'Next Accounting Period';
+------------------------+
| Next Accounting Period |
+------------------------+
|                 200501 |
+------------------------+

Functions such as this one are particularly useful when you’re building a script or program, and you need to design an SQL statement that will account for accounting periods that roll into new years.

Get MySQL in a Nutshell 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.