quarters_sub
Subtracts a specified number of quarters from the date. One quarter equals three months.
Syntaxβ
DATETIME quarters_sub(DATETIME expr1, INT expr2);
Parametersβ
-
expr1: the specified date. It must be of the DATETIME or DATE type. -
expr2: the quarters to subtract. It must be of the INT type. It can be greater, equal, or less than zero. A negative value adds quarters toexpr1.
Return valueβ
Returns a DATETIME value.
Examplesβ
select quarters_sub('2022-02-28 15:04:05', 1);
+----------------------------------------+
| quarters_sub('2022-02-28 15:04:05', 1) |
+----------------------------------------+
| 2021-11-28 15:04:05 |
+----------------------------------------+
select quarters_sub('2022-02-28', 1);
+-------------------------------+
| quarters_sub('2022-02-28', 1) |
+-------------------------------+
| 2021-11-28 00:00:00 |
+-------------------------------+