Skip to main content

YEARS_DIFF

Description

Calculates the difference in years between two datetime values.

Syntax

YEARS_DIFF(<enddate>, <startdate>)

Parameters

ParameterDescription
<enddate>The end date, which can be of type DATETIME or DATE
<startdate>The start date, which can be of type DATETIME or DATE

Return Value

Returns a value of type INT, representing the number of years between the two dates.

Example

SELECT YEARS_DIFF('2020-12-25', '2019-10-25');
+----------------------------------------------------------+
| years_diff('2020-12-25 00:00:00', '2019-10-25 00:00:00') |
+----------------------------------------------------------+
| 1 |
+----------------------------------------------------------+