Curriculum
Course: MYSQL
Login

Curriculum

MYSQL

MySQL References

0/140
Text lesson

PERIOD_DIFF

Example

Calculate and return the difference in months between two specified periods.

SELECT PERIOD_DIFF(201710201703);

Definition and Usage

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

Note: both period1 and period2 must be in the same format.

Syntax

PERIOD_DIFF(period1period2)

Parameter Values

Parameter

Description

period1

Mandatory: A period formatted as YYMM or YYYYMM

period2

Mandatory: Another period formatted as YYMM or YYYYMM

Technical Details

Works in:

 From MySQL version 4.0

More Examples

Example

Calculate and return the difference in months between two specified periods.

SELECT PERIOD_DIFF(201703201803);

Example

Calculate and provide the difference in months between two specified periods.

SELECT PERIOD_DIFF(17031612);