totn MariaDB Functions

MariaDB: PERIOD_DIFF Function

This MariaDB tutorial explains how to use the MariaDB PERIOD_DIFF function with syntax and examples.

Description

The MariaDB PERIOD_DIFF function returns the difference in months between two periods (formatted as YYMM or YYYYMM).

Syntax

The syntax for the PERIOD_DIFF function in MariaDB is:

PERIOD_DIFF( period1, period2 )

Parameters or Arguments

period1
A period formatted as either YYMM or YYYYMM.
period2
A period formatted as either YYMM or YYYYMM.

Note

  • The parameters period1 and period2 must be formatted as either YYMM or YYYYMM, but do not have to be the same format as each other. So period1 could be formatted as YYMM and period2 could be formatted as YYYYMM, or vice versa.

Applies To

The PERIOD_DIFF function can be used in the following versions of MariaDB:

  • MariaDB 10

Example

Let's look at some MariaDB PERIOD_DIFF function examples and explore how to use the PERIOD_DIFF function in MariaDB.

For example:

SELECT PERIOD_DIFF(201406, 201405);
Result: 1

SELECT PERIOD_DIFF(201510, 201410);
Result: 12

SELECT PERIOD_DIFF(201410, 201510);
Result: -12

SELECT PERIOD_DIFF(1406, 1404);
Result: 2

SELECT PERIOD_DIFF(201406, 1401);
Result: 5

SELECT PERIOD_DIFF(1406, 201401);
Result: 5