# SUBTRACT\_FROM\_DATE

**The function SUBTRACT\_FROM\_DATE subtracts a given number of years, months, weeks, or days from a given Date.**

This function takes three pieces of input: a [Date](../../variable-data-types/the-date-variable-data-type), a [Number](../../variable-data-types/the-number-variable-data-type), and a [string](../../variable-data-types/the-text-variable-data-type). The string designates which value in the given Date will be modified: "year", "month", "week", or "day". This function subtracts the given Number from the designated value, and returns the resulting [Date](../../variable-data-types/the-date-variable-data-type). Calculation takes into account irregularities such as daylight savings time and leap years.

#### Declaration

```javascript
SUBTRACT_FROM_DATE(date, number, unit_string) -> modified_date
```

&#x20;

#### Parameters

`date` (required, type: `Date`) Any valid Date.

`number` (required, type: `Number`) The number of units to be subtracted from the given Date. This number can be negative; if given a negative number, SUBTRACT\_FROM\_DATE will subtract the negative number from the specified value in the Date, ultimately _increasing_ the original value.

`unit_string` (required, type: `string`) The units in the given Date that will be modified: "year", "month", "week", or"day". In order to be correctly parsed by SUBTRACT\_FROM\_DATE, the given string must exactly match one of the relevant values given by [this table](https://github.com/airkit/airkit-docs/blob/master/docs/v18-4/time-unit-values.md).

#### Return Values

`modified_date` (type: `Date`) The Date that results from subtracting given number of units from the given Date. Calculation takes into account irregularities such as daylight savings time and leap years.

#### Examples

Assume all examples have access to the following Date:

```javascript
example_date = {  
  "day": 14,
  "month": 4,
  "year": 2022
}
```

The following example takes the date described in `example_date` and subtracts 3 days from it. Not that the returned Date is identical to `example_date`, save for the day value:

```javascript
SUBTRACT_FROM_DATE(example_date, 3, "day") -> {
  "day": 11,
  "month": 4,
  "year": 2022
}  
```

The following example takes the date described in `example_date` and subtracts 6 months from it. Note how this results in a change not only in the month value of the resulting Date, but also in the the year:

```javascript
SUBTRACT_FROM_DATE(example_date, 6, "month") -> {
  "day": 14,
  "month": 10,
  "year": 2021
}
```

The following example takes the date and time described in `example_date` and subtracts -1 day from it. Note how this effectively adds 1 to the given day value:

```javascript
SUBTRACT_FROM_DATE(example_date, -1, "day") -> {
  "day": 15,
  "month": 4,
  "year": 2022
}  
```

If SUBTRACT\_FROM\_DATE is given a `unit_string` it cannot parse, it simply returns the given Date unmodified, such as in the following example:

```javascript
SUBTRACT_FROM_DATE(example_date, 33, "This is a string") -> {
  "day": 14,
  "month": 4,
  "year": 2022
}
```

&#x20;

#### Discussion

Subtracting negative values is the same as adding positive values, allowing SUBTRACT\_FROM\_DATE to mimic the functionality of [ADD\_TO\_DATE](add_to_date).
