MariaDB PERIOD_ADD() Function
In MariaDB, PERIOD_ADD()
is a built-in function that adds the specified number of months to the specified year and month and returns the result as a year and month.
MariaDB PERIOD_ADD()
Syntax
This is the syntax of the MariaDB PERIOD_ADD()
function:
PERIOD_ADD(period, month_number)
Parameters
period
-
Required. Period in
YYYYMM
orYYMM
format. month_number
-
Required. The number of months to add to
period
.
If you supply the wrong number of arguments, MariaDB will report an error: ERROR 1582 (42000): Incorrect parameter count in the call to native function 'PERIOD_ADD'
.
Return value
The MariaDB PERIOD_ADD()
function adds the specified number of months to the specified year and month and returns the result as a number. The return value of the PERIOD_ADD()
function is a number in the format YYYYMM
.
For two-digit years, MariaDB handles them as follows:
- Values from
00
to69
will be converted2000
to2069
- Values from
70
to99
will be converted1970
to1999
If the argument is NULL
, the PERIOD_ADD()
function will return NULL
.
MariaDB PERIOD_ADD()
Examples
Example 1 − YYYYMM
SELECT
PERIOD_ADD(202301, 1),
PERIOD_ADD(202301, 2),
PERIOD_ADD(202301, 3),
PERIOD_ADD(202301, 4),
PERIOD_ADD(202301, 5),
PERIOD_ADD(202301, 6),
PERIOD_ADD(202301, 7),
PERIOD_ADD(202301, 8),
PERIOD_ADD(202301, 9),
PERIOD_ADD(202301, 10),
PERIOD_ADD(202301, 11),
PERIOD_ADD(202301, 12)\G
Output:
PERIOD_ADD(202301, 1): 202302
PERIOD_ADD(202301, 2): 202303
PERIOD_ADD(202301, 3): 202304
PERIOD_ADD(202301, 4): 202305
PERIOD_ADD(202301, 5): 202306
PERIOD_ADD(202301, 6): 202307
PERIOD_ADD(202301, 7): 202308
PERIOD_ADD(202301, 8): 202309
PERIOD_ADD(202301, 9): 202310
PERIOD_ADD(202301, 10): 202311
PERIOD_ADD(202301, 11): 202312
PERIOD_ADD(202301, 12): 202401
Example 2 −YYMM
For two-digit years, MariaDB handles them as follows:
- Values from
00
to69
will be converted2000
to2069
- Values from
70
to99
will be converted1970
to1999
SELECT
PERIOD_ADD(0002, 6),
PERIOD_ADD(6902, 6),
PERIOD_ADD(7002, 6),
PERIOD_ADD(9902, 6)\G
Output:
PERIOD_ADD(0002, 6): 200008
PERIOD_ADD(6902, 6): 206908
PERIOD_ADD(7002, 6): 197008
PERIOD_ADD(9902, 6): 199908
Conclusion
In MariaDB, PERIOD_ADD()
is a built-in function that adds the specified number of months to the specified year and month and returns the result as a number.