MySQL PERIOD_ADD() Function
In MySQL, the PERIOD_ADD()
function adds the specified number of months to the specified year-month and returns the result as year-month.
PERIOD_ADD()
Syntax
Here is the syntax of MySQL PERIOD_ADD()
function:
PERIOD_ADD(period, month_number)
Parameters
period
- Required. The period in
YYYYMM
orYYMM
format. month_number
- Required. The number of months to add to
period
.
Return value
The MySQL PERIOD_ADD()
function adds the specified number of months to the specified year-month and returns the result as year-month. The PERIOD_ADD()
function return value is a number in the format YYYYMM
.
The PERIOD_ADD()
function will return NULL
if any argument is NULL
.
PERIOD_ADD()
Examples
Here are some examples of the PERIOD_ADD()
function.
SELECT
PERIOD_ADD(202201, 1),
PERIOD_ADD(202201, 2),
PERIOD_ADD(202201, 3),
PERIOD_ADD(202201, 4),
PERIOD_ADD(202201, 5),
PERIOD_ADD(202201, 6),
PERIOD_ADD(202201, 7),
PERIOD_ADD(202201, 8),
PERIOD_ADD(202201, 9),
PERIOD_ADD(202201, 10),
PERIOD_ADD(202201, 11),
PERIOD_ADD(202201, 12)\G
PERIOD_ADD(202201, 1): 202202
PERIOD_ADD(202201, 2): 202203
PERIOD_ADD(202201, 3): 202204
PERIOD_ADD(202201, 4): 202205
PERIOD_ADD(202201, 5): 202206
PERIOD_ADD(202201, 6): 202207
PERIOD_ADD(202201, 7): 202208
PERIOD_ADD(202201, 8): 202209
PERIOD_ADD(202201, 9): 202210
PERIOD_ADD(202201, 10): 202211
PERIOD_ADD(202201, 11): 202212
PERIOD_ADD(202201, 12): 202301