MySQL: PERIOD_ADD Function

  • Post author:
  • Post category:MySQL
  • Post comments:1 Comment
MySQL PERIOD_ADD Function

In this guide, we will explain 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 :

  • 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 PERIOD_ADD function examples and explore how to use the PERIOD_ADD function.

For example:

mysql> SELECT PERIOD_ADD(201402,5);
Result: 201407

mysql> SELECT PERIOD_ADD(201402,6);
Result: 201408

mysql> SELECT PERIOD_ADD(201402,12);
Result: 201502

mysql> SELECT PERIOD_ADD(201402,16);
Result: 201506

mysql> SELECT PERIOD_ADD(201402,-1);
Result: 201401

mysql> SELECT PERIOD_ADD(1402,5);
Result: 201407

mysql> SELECT PERIOD_ADD(1402,6);
Result: 201408

Next Topic : Click Here

This Post Has One Comment

Leave a Reply