time_subtract

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

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

Syntax

{{ 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:

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

Get orders from the last 7 days:

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

Calculate a refund deadline:

Look back by hours:

Filter by date range:

Combine with in_timezone:

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

Last updated