YEARS_SUB
Descriptionβ
Returns a new datetime value that is the result of subtracting a specified number of years from the input datetime.
Syntaxβ
YEARS_SUB(<date>, <years>)
Parametersβ
Parameter | Description |
---|---|
<date> | The input datetime value, which can be of type DATETIME or DATE |
<years> | The number of years to subtract, of type INT |
Return Valueβ
Returns a value with the same type as the input <date>
(DATETIME or DATE), representing the time value after subtracting the specified number of years from the input datetime.
Exampleβ
SELECT YEARS_SUB('2020-02-02 02:02:02', 1);
+-------------------------------------+
| years_sub('2020-02-02 02:02:02', 1) |
+-------------------------------------+
| 2019-02-02 02:02:02 |
+-------------------------------------+