Date variables in templates reference

Last updated at:

You will learn

Learn how to dynamically populate and format dates in your Klaviyo templates. You can input dates from profile properties (e.g., birthday) into any message, or event metadata (e.g., placed order date) into flow messages triggered by that event. 

Populate current day, week, month, or year

Date tags give you a quick way to insert the time of a campaign into a message. The date is in the time zone of your account. 

  • Current day of month: The current day of the month is {% current_day %}
    The current day of the month is 5
  • Current day of the week: The current day of the week is {% current_weekday %}
    The current day of the week is Friday
  • Current month: The current month is {% current_month_name %}
    The current month is September
  • Current year: The current year is {% current_year %}
    The current year is 2021

Currently, we only support English names for months and days of the week.

Populate a dynamic date as event variable in flow email

Let's say you are sending a thank you email through a flow that triggers whenever a customer places an order. You may want to add a sentence that says, "Thank you for your order on _____" and specify the date of the placed order.

If you look at the data Klaviyo receives along with an event, like a Placed Order event, you should be able to find a variable there that represents the order date. Look for a property called "order date" or something similar, as the property name will vary depending on your data source.

Once you find this variable, you'll probably next notice that the format of this date is not ideal to use in a template -- it's a UTC timestamp that doesn't look great in an email, for example:

A UTC formatted timestamp

If you want to populate this date in a more customer-friendly format, you will need to apply a few filters. Klaviyo supports most of the filters used by the Django template language. For this use case, you will need to use the following filters:

  • Format_date_string 
    This filter parses and converts the string of characters sliced from the full UTC timestamp to an actual date; this is necessary so that you can use the date filter to format it
  • Date
    This is where you get to choose how you want your date formatted; Django has a chart that outlines how to approach this

To apply these filters, separate them with a pipe (|) and no spaces in between:

{{ your_variable|format_date_string|date:'F d, o' }}

The above would turn this:


into this: 

February 11, 2016

Below are some additional common date formats, along with the formatting used to display them. 

February 26, 2016 

{{ your_variable|format_date_string|date:'F d, o' }}

26 February 2016

{{ your_variable|format_date_string|date:'d F o' }}


{{ your_variable|format_date_string|date:'m-d-Y' }}


{{ your_variable|format_date_string|date:'d-m-Y' }}

2/26/16 (no leading 0s)

{{ your_variable|format_date_string|date:'n/j/y' }}

26/2/16 (no leading 0s)

{{ your_variable|format_date_string|date:'j/n/y' }}

Feb 11

{{ your_variable|format_date_string|date:'M d' }}

11 Feb

{{ your_variable|format_date_string|date:'d M' }}

For a full list of date format options, reference Django’s date format documentation

Using the “today” variable

The today variable allows you to display today’s date at the time a message is sent. To display today’s date, use this code: 

{% today "%Y-%m-%d" as today %} {{ today }}

The date will display in this format: 2021-03-18

To apply different formatting, apply the filters from the section above to the {{ today }} variable. For example, {% today '%Y-%m-%d' as today %} {{ today|format_date_string|date:'m/d/Y' }} would render using the format MM/DD/YYYY. 

Calculating a future date

If you’d like to display a future date relative to the day a message is sent, apply the days_later filter to the today variable outlined above, like this: 

{% today "%Y-%m-%d" as today %} {{ today|days_later:5 }}

This variable will display the date 5 days after a message is sent. So, if the message was sent on March 18, the date displayed would be 2021-03-23. 

This filter can be combined with the formatting filters outlined above to use a different date format. Take this code as an example: 

{% today '%Y-%m-%d' as today %} {{ today|days_later:5|format_date_string|date:'M d' }}

If the message was sent on March 18, this would render as Mar 23. 

Additional resources

Was this article helpful?
76 out of 113 found this helpful