WEEKS_SUB
Description
Subtracts a specified number of weeks from a specified date or time value (i.e., subtracts weeks * 7 days).
Syntax
WEEKS_SUB(<date_value>, <week_period>)
Required parameters
Parameter | Description |
---|---|
date_value | DATE or DATETIME type input value. |
week_period | Integer, representing the number of weeks to subtract (positive to decrease, negative to increase). |
Example
-
Subtract one week from the datetime
2020-02-02 02:02:02
select weeks_sub("2020-02-02 02:02:02", 1);
+-------------------------------------+
| weeks_sub('2020-02-02 02:02:02', 1) |
+-------------------------------------+
| 2020-01-26 02:02:02 |
+-------------------------------------+ -
Subtract one week from the date
2020-02-02
select weeks_sub("2020-02-02", 1);
+--------------------------------------------+
| weeks_sub(cast('2020-02-02' as DATEV2), 1) |
+--------------------------------------------+
| 2020-01-26 |
+--------------------------------------------+