# 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`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.datajet-app.com/liquid/filters/time_subtract.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
