> For the complete documentation index, see [llms.txt](https://docs.datajet-app.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.datajet-app.com/liquid/filters/time_subtract.md).

# time\_subtract

Subtracts a specified amount of time from a date. Returns the result as an ISO 8601 string.

```liquid
{% assign yesterday = "now" | time_subtract: 1, "days" %}
{% log yesterday %}
```

#### Syntax

```liquid
{{ date | time_subtract: amount, unit }}
```

| Parameter | Description                                                                                |
| --------- | ------------------------------------------------------------------------------------------ |
| `date`    | Starting date — a date string, `"now"`, or `"today"`                                       |
| `amount`  | Number of units to subtract                                                                |
| `unit`    | Time unit: `"years"`, `"months"`, `"weeks"`, `"days"`, `"hours"`, `"minutes"`, `"seconds"` |

#### Return Value

Returns a string in `YYYY-MM-DDTHH:mm:ss` format.

#### Examples

**Get yesterday's date:**

```liquid
{% assign yesterday = "now" | time_subtract: 1, "days" %}
{% log yesterday %}
```

**Get orders from the last 7 days:**

```liquid
{% assign week_ago = "now" | time_subtract: 7, "days" %}
{% log "Fetching orders since: " | append: week_ago %}
```

**Calculate a refund deadline:**

```liquid
{% assign refund_cutoff = order.created_at | time_subtract: 0, "days" | time_add: 30, "days" %}
{% assign now = "now" | time_add: 0, "seconds" %}
{% log "Refund deadline: " | append: refund_cutoff %}
```

**Look back by hours:**

```liquid
{% assign two_hours_ago = "now" | time_subtract: 2, "hours" %}
{% log "Since: " | append: two_hours_ago %}
```

**Filter by date range:**

```liquid
{% assign start_date = "now" | time_subtract: 30, "days" %}
{% assign end_date = "now" | time_add: 0, "seconds" %}
{% log "Date range: " | append: start_date | append: " to " | append: end_date %}
```

**Combine with in\_timezone:**

```liquid
{% assign past = "now" | time_subtract: 1, "weeks" | in_timezone: shop.timezone %}
{% log past %}
```

#### Notes

* Accepts `"now"` or `"today"` as the current date/time
* The output format is always `YYYY-MM-DDTHH:mm:ss` — use the `date` filter to reformat
* See also: `time_add`, `in_timezone`
