time_add

Adds a specified amount of time to a date. Returns the result as an ISO 8601 string.

{% assign tomorrow = "now" | time_add: 1, "days" %}
{% log tomorrow %}

Syntax

{{ date | time_add: amount, unit }}
Parameter
Description

date

Starting date — a date string, "now", or "today"

amount

Number of units to add

unit

Time unit: "years", "months", "weeks", "days", "hours", "minutes", "seconds"

Return Value

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

Examples

Add days:

{% assign delivery_date = order.created_at | time_add: 5, "days" %}
{% log "Expected delivery: " | append: delivery_date %}

Add hours from now:

{% assign expires_at = "now" | time_add: 24, "hours" %}
{% log "Expires at: " | append: expires_at %}

Add months:

Schedule a follow-up:

Calculate an expiration date and format it:

Output:

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_subtract, in_timezone

Last updated