Calculates the difference in years between two datetime values.
YEARS_DIFF(<enddate>, <startdate>)
| Parameter | Description |
|---|---|
<enddate> | The end date, which can be of type DATETIME or DATE |
<startdate> | The start date, which can be of type DATETIME or DATE |
Returns a value of type INT, representing the number of years between the two dates.
SELECT YEARS_DIFF('2020-12-25', '2019-10-25');
+----------------------------------------------------------+ | years_diff('2020-12-25 00:00:00', '2019-10-25 00:00:00') | +----------------------------------------------------------+ | 1 | +----------------------------------------------------------+