This tutorial explains how to use the MySQL PERIOD_ADD function with syntax and examples.
The MySQL PERIOD_ADD function takes a period (formatted as YYMM or YYYYMM) and adds a specified number of months to it.
The syntax for the PERIOD_ADD function in MySQL is:
PERIOD_ADD( period, number )
A period formatted as either YYMM or YYYYMM.
The number of months to add to the period. It can be a positive or negative value.
The PERIOD_ADD function can be used in the following versions of MySQL:
Let's look at some MySQL PERIOD_ADD function examples and explore how to use the PERIOD_ADD function in MySQL.
For example:
mysql> SELECT PERIOD_ADD(201402,5);
Output: 201407
mysql> SELECT PERIOD_ADD(201402,6);
Output: 201408
mysql> SELECT PERIOD_ADD(201402,12);
Output: 201502
mysql> SELECT PERIOD_ADD(201402,16);
Output: 201506
mysql> SELECT PERIOD_ADD(201402,-1);
Output: 201401
mysql> SELECT PERIOD_ADD(1402,5);
Output: 201407
mysql> SELECT PERIOD_ADD(1402,6);
Output: 201408