Formatting dates with liquid syntax

Overview

Ortto allows you to use Liquid template language in your email, SMS, and push notifications. This makes it possible to display dynamic dates and times, calculate future or past dates, and format timestamps based on your messaging needs.

By combining merge tags with Liquid date filters, you can create messages that automatically update such as showing today’s date, calculating relative timeframes, or formatting dates for different timezones.

TIP: You can use the `assign ` operator to create a variable to modify dates or timeframe values.

Learn more about personalizing campaign content with Liquid.

Description

Format

Example Output

Notes

Change timezone

{% assign varTZ = 5 | times: 3600 %} {{ 'now' | date: "%s" | minus: varTZ | date: "%D %l:%M%p" }}

04/17/23 3:40PM

Sets a timezone offset in seconds (UTC-5 = 5 × 3600). Converts now to seconds, applies the offset, then formats the date. Variables must start with var.

Current year

{{ "now" | date: "%Y" }}

2023

Returns the current year in four-digit format.

Last month

{% assign varLastMonth = "now" | date: "%Y-%m-01" | date: "%s" | minus: 1 | date: "%B" %} {{ varLastMonth }}

April

Calculates the previous month by moving to the first day of the current month, subtracting one second, and formatting the result.

Time in timezone

{{ people.created | timeInTimezone: 'Asia/Shanghai', 'mdy12' }}

Jan 01 2023 12:00 AM

Converts a date/time value to the specified timezone and format.

Today’s date

{{ 'now' | date: "%B %d, %Y" }}

April 17, 2023

Formats today’s date using a custom date string.

Tomorrow

{{ 'now' | date: "%s" | plus: 86400 | date: "%D" }}

04/18/23

Converts today to seconds, adds one day (86,400 seconds), and formats the result.

Two weeks from today

{% assign varTwoWeeks = 14 | times: 86400 %} {{ 'now' | date: "%s" | plus: varTwoWeeks | date: "%D" }}

05/01/23

Adds 14 days in seconds to today’s date, then formats the result. Variables must start with var.

Current week range

{% assign varDayOfWeek = "now" | date: "%u" %} {% assign varTimeSinceSunday = varDayOfWeek | times: 86400 %} {% assign varSunday = "now" | date: "%s" | minus: varTimeSinceSunday %} {% assign varSaturday = varSunday | plus: 518400 %} {{ varSunday | date: "%d %b" }} - {{ varSaturday | date: "%d %b" }}

15 Oct - 21 Oct

Calculates the current week from Sunday to Saturday by converting dates to seconds and adding or subtracting day offsets. Outputs a formatted date range.