Mysql Period_add Function

MySQL: PERIOD_ADD Function

This tutorial explains how to use the MySQL PERIOD_ADD function with syntax and examples.

Description

The MySQL PERIOD_ADD function takes a period (formatted as YYMM or YYYYMM) and adds a specified number of months to it.

Syntax

The syntax for the PERIOD_ADD function in MySQL is:

PERIOD_ADD( period, number )

Parameters or Arguments

period

A period formatted as either YYMM or YYYYMM.

number

The number of months to add to the period. It can be a positive or negative value.

Note

  • The PERIOD_ADD function will return the result formatted as YYYYMM.

Applies To

The PERIOD_ADD function can be used in the following versions of MySQL:

  • MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23

Example

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