MySQL PERIOD_DIFF() Function
THE WORLD'S LARGEST WEB DEVELOPER SITE

MySQL PERIOD_DIFF() Function

❮ MySQL Functions

Example

Return the difference in months between two periods:

SELECT PERIOD_DIFF(201710, 201703);
Try it Yourself »

Definition and Usage

The PERIOD_DIFF() function returns the difference in months between two periods.

Syntax

PERIOD_DIFF(period1, period2)

Parameter Values

Parameter Description
period1 Required. A period formatted as YYMM or YYYYMM
period2 Required. A period formatted as YYMM or YYYYMM

Technical Details

Works in: MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23

More Examples

Example

Return the difference in months between two periods:

SELECT PERIOD_DIFF(201703, 201803);
Try it Yourself »

Example

Return the difference in months between two periods:

SELECT PERIOD_DIFF(1703, 1612);
Try it Yourself »

❮ MySQL Functions