How to Format Date Variables in Templates

Last updated at:

Populate Current Day, Week, Month, or Year

Date tags give you a quick way to insert the time of a campaign into an email. 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 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. This variable might not be labeled "order date," but there is likely a variable that represents the timestamp of the placed order. This will vary depending on your integration.

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:


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, you will 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

Django's date filter takes certain characters that all produce different outputs. For example:

  • Y-m-d h:mm:ss
    • 2018-08-03 09:55:04
  • F d, o
    • February 11, 2016
  • D d M Y
    • Thu 11 Feb 2016
    • 02/11/2016

Learn more

To learn more about all the date formatting options available, check out Django's page on date filters.
Was this article helpful?
16 out of 31 found this helpful