You can use date and time helpers to compare and modify numeric strings that are formatted as dates and times.
# In this article
# Comparing dates
The #ifGte, #ifGt, #ifLte, and #ifLt helpers are generally used to
compare numbers, but you can use them to compare dates if you format the dates
as numbers (no hyphens, spaces, or slashes). To do this, use the dateFormat
helper to format the values of date fields as numeric strings (for example,
yyyyMMddHHmmss).
# Check if a date is on or after another date
The #ifGte helper checks to see if a date is greater than or equal to the
value of another date. If it is, the associated content is displayed. Otherwise,
the content is not displayed.
# Properties
fieldName1 — The name of the user or event data field containing the date you
want to compare to another.
fieldName2 — The name of the user or event data field containing the date you
want to compare the first date to.
content — The content you want to display if the first date is greater than
(i.e., more recent) or equal to the second date.
NOTE
Instead of fieldName2, you could use the dateMath helper to compare fieldName1
to a relative date (for example, to check if the date in fieldName1 occurred
within the past month).
# Format
# Example
| Code | Example trialStartDate value | Output |
|---|---|---|
| 2025-02-12 | Your Fiterable free trial has ended |
# Check if a date is after another date
The #ifGt helper checks to see if a date is greater than the value of another
date. If it is, the associated content is displayed. Otherwise, the content is
not displayed.
# Properties
fieldName1 — The name of the user or event data field containing the date you
want to compare to another.
fieldName2 — The name of the user or event data field containing the date you
want to compare the first date to.
content — The content you want to display if the first date is greater than
(i.e., more recent) the second date.
NOTE
Instead of fieldName2, you could use the dateMath helper to compare fieldName1
to a relative date (for example, to check if the date in fieldName1 occurred
within the past month).
# Format
# Example
| Code | Example trialStartDate value | Output |
|---|---|---|
| 2025-02-12 | Your Fiterable free trial has ended |
# Check if a date is on or before another date
The #ifLte helper checks to see if a date is less than or equal to the value
of another date. If it is, the associated content is displayed. Otherwise, the
content is not displayed.
# Properties
fieldName1 — The name of the user or event data field containing the date you
want to compare to another.
fieldName2 — The name of the user or event data field containing the date you
want to compare the first date to.
content — The content you want to display if the first date is less than
(i.e., less recent) or equal to the second date.
NOTE
Instead of fieldName2, you could use the dateMath helper to compare fieldName1
to a relative date (for example, to check if the date in fieldName1 occurred
within the past month).
# Format
# Example
| Code | Example signupDate value | Output |
|---|---|---|
| 2025-02-12 | signupDate was before June 30, 2025 |
# Check if a date is before another date
The #ifLt helper checks to see if a date is less than the value of another
date. If it is, the associated content is displayed. Otherwise, the content is
not displayed.
# Properties
fieldName1 — The name of the user or event data field containing the date you
want to compare to another.
fieldName2 — The name of the user or event data field containing the date you
want to compare the first date to.
content — The content you want to display if the first date is less than
(i.e., less recent) the second date.
NOTE
Instead of fieldName2, you could use the dateMath helper to compare fieldName1
to a relative date (for example, to check if the date in fieldName1 occurred
within the past month).
# Format
# Example
| Code | Example signupDate value | Output |
|---|---|---|
| 2025-02-12 | signupDate was before June 30, 2025 |
# Formatting dates
The dateFormat Handlebars helper outputs a given date in the specified format.
There are several options you can specify for displaying dates in different
formats.
# Display the full alphanumeric date (with day of the week)
Use the format="full" option to display the full, unabbreviated date, including
the day of the week.
# Properties
fieldName — The name of the user or event data field containing the date you
want to format.
# Format
# Example
| Code | Example signupDate value | Output |
|---|---|---|
| 2025-02-12 | Wednesday, February 12, 2025 |
# Display the full alphanumeric date (without day of the week)
Use the format="long" option to display the full, unabbreviated date without
the day of the week.
# Properties
fieldName — The name of the user or event data field containing the date you
want to format.
# Format
# Example
| Code | Example signupDate value | Output |
|---|---|---|
| 2025-02-12 | February 12, 2025 |
# Display the abbreviated alphanumeric date
Use the format="medium" option to display the abbreviated alphanumeric date
without the day of the week.
# Properties
fieldName — The name of the user or event data field containing the date you
want to format.
# Format
# Example
| Code | Example signupDate value | Output |
|---|---|---|
| 2025-02-12 | Feb 12, 2025 |
# Display the numeric date
Use the format="short" option to display the date in numeric DD/MM/YY format.
# Properties
fieldName — The name of the user or event data field containing the date you
want to format.
# Format
# Example
| Code | Example signupDate value | Output |
|---|---|---|
| 2025-02-12 | 02/12/25 |
NOTE
This helper formats dates according to the American convention (listing the day of the week before the month). To change this, specify a locale code that corresponds to your preferred date convention.
# Display a date according to a locale
Specify a locale code along
with your preferred formatting option (full/long/medium/short) to
display the date according to the norms of a region/language. This rearranges
the order of day/month/year as needed, translates month names to the associated
language, and adds the appropriate punctuation.
# Properties
fieldName — The name of the user or event data field containing the date you
want to format.
format — The formatting option (full/long/medium/short) you want to
use to format the date.
locale — The locale code you want to use to format the date.
# Format
# Example
| Code | Example signupDate value | Output |
|---|---|---|
| 2025-02-12 | 12. Februar 2025 |
# Display the date according to a time zone
Specify a time zone to display a date based on a time zone. This can be helpful if you have customers in different regions and time zones around the world and want to display dates and times correctly for each user.
NOTE
The tz option of the dateFormat helper does not translate or rearrange
dates according to the associated regional/language conventions for a time zone.
To do this, include the locale helper.
# Properties
fieldName1 — The name of the user or event data field containing the date you
want to format.
fieldName2 — The name of the user or event data field containing the time zone
you want to use to format your date. (Alternatively, you can include a
TZ time zone code
instead of referencing the value of a field.)
# Format
# Example
| Code | Example signupDate value | Output |
|---|---|---|
| 2018-01-01 00:00:00 | Dec 31, 2017 |
# Calculating dates
The dateMath helper uses a mathematical expression to calculate a new date
before or after a specified date. Input date values must be in ISO 8601
format.
# Calculate a date from another date
You can use the dateMath helper to add or subtract some period of time from an
input date and display the resulting date. The dateMath helper supports the
following mathematical operations:
-
-— Subtract -
+- Add -
/— Round
To learn more about adding, subtracting, multiplying, and dividing by date and time values, see Handlebars Reference: Math Helpers and Using Relative Dates in Segments and Journeys.
# Properties
inputDate — The name of the user or event data field containing the date
value you wish to calculate another date from (alternatively, this property can
be a literal string value placed in double quotes).
dateCalculation — The amount of time you wish to add or subtract from your input
date.
# Format
# Example
| Code | Example signupDate value | Output |
|---|---|---|
| 2025-01-01 00:00:00 | Jan 8, 2025 |
# Calculate a date from now
You can use dateMath to add or subtract a certain amount of time from now
(the current moment at send time).
# Properties
now — The current moment in time, which functions as the input date.
dateCalculation — The amount of time you wish to add or subtract from the
current date/time.
# Format
# Example
| Code | Example signupDate value | Output |
|---|---|---|
| 2025-04-04 | Apr 3, 2025 |
# Calculate the number of days away from a date
You can use the dateMath helper to determine how many days there are between a
date from a user or event data field and now (the current date at send time).
# Calculate a person's age
# Display the current date and time
now displays the current date and time. By default, now displays the date in
"medium" format (for example, "Apr 7, 2025"), but you can change this by
specifying a different formatting option (see Formatting Dates).
# Format
For example:
# Display the current year
# Display the current day of the week
# Display the current time
timestamp displays the current time in epoch milliseconds (the number of
milliseconds since 1970-01-01 00:00:00 UTC).
# Format
# Example
| Code | Example current time value | Output |
|---|---|---|
| Tuesday, April 8, 2025 5:11:00.210 PM | 1744132260210 |
# Time units reference
When working with dates and times using Handlebars, you can use the following date and time units to specify your preferred formatting and display options.
| Code | Meaning | Output | Examples |
|---|---|---|---|
| y, yy, yyyy | Year | Number | 2025, 25, 2025 |
| M, MM, MMM, MMMM | Month | Number/Text | 4, 04, Apr, April |
| d, dd | Day of month | Number | 8, 08 |
| D, DD, DDD | Day of year | Number | 98 |
| e | Day of week (Monday = 1) | Number | 2 |
| E, EEEE | Day of week | Text | Tue, Tuesday |
| a | Halfday of day | Text | PM |
| w | Week of year | Number | 27 |
| h | Clock hour of halfday (1-12) | Number | 12 |
| H | Hour of day (0-23) | Number | 0 |
| k | Clock hour of day (1-24) | Number | 16 |
| K | Hour of halfday (0-11) | Number | 4 |
| m | Minute of hour | Number | 30 |
| s | Second of minute | Number | 55 |
| S | Milliseconds | Number | 978 |
| z | Time zone | Text | Pacific Standard Time, PST |
| Z | Time zone offset/ID | Number/Text | -0800, -08:00, America/Los_Angeles |
| C | Century | Number | 20 |
| G | Era | Text | AD |
| now | Current date/time (standard) | Text/number | Apr 8, 2025 |
| timestamp | Current UNIX time | Number | 1744310391343 |
# Want to learn more?
For more information about some of the topics in this article, check out these resources. Iterable Academy is open to everyone — you don't need to be an Iterable customer!
Iterable Academy
Support docs