MySQL PERIOD_ADD() Function

MySQL | PERIOD_ADD() Function: Learn about the PERIOD_ADD() function, how it works, its usages, syntax, and examples.
Submitted by Apurva Mathur, on October 10, 2022

PERIOD_ADD() Function

When you want to add some number of months to a period then in such case, we can use the PERIOD_ADD() function. This function adds a number of months to the period (here period denotes the dates which are in the form of YYMM or YYYYMM).

PERIOD_ADD() Syntax

SELECT PERIOD_ADD(period date, months);

PERIOD_ADD() Parameter(s)

This function takes two parameters:

  • period date: This means you have to provide a fixed period/date which should be in the form of YYMM or YYYYMM.
  • months: This denotes the number of months that you want to add to your period.

PERIOD_ADD() Return Value

This function will return the number in the format of YYYYMM after adding the month to the period.

MySQL PERIOD_ADD() Function Example 1

SELECT PERIOD_ADD(201902,1);

201902 means 2019 is the year and 02 is the month and if we add 1 using the PERIOD_ADD() function then it should return 201903 which is 3rd month of the 2019 year.

Example 1: MySQL PERIOD_ADD() Function

MySQL PERIOD_ADD() Function Example 2

SELECT PERIOD_ADD(2204,3);

In this example the period is written in the YYMM format, that is 22 here signifies the year 2022, and 04 signifies the month, and now if I’ll add 3 to this period then it will return us 202207, which means it will add 3 to the month which we have provided.

Example 2: MySQL PERIOD_ADD() Function



Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.