Solved

Need some help for a date formula calculation with Django

  • 13 October 2023
  • 3 replies
  • 145 views

Badge +2

Hello there :)

We need some help with Django tags. In a Happy Anniversary Flow Message we want to include something personalised like “Your first purchase order was x years ago!” for which x should be CURRENT YEAR minus YEAR OF FIRST PURCHASE ORDER. We know how to show the variable separately but we don’t know how to subtract them. Can someone help us here? Is it even possible?

 

icon

Best answer by Taylor Tarpley 20 February 2024, 03:06

View original

3 replies

Userlevel 7
Badge +60

Hi there @recirocketteam

 

Welcome to the Community! Happy to help! 

 

The possibility of doing this math between the two variables in a template is a bit complex as it will depend on how the data is passed, the data types, etc. Do you mind sending a screenshot of the event data and event properties to see how they are appearing in your template? 

 

Please be sure not to share sensitive information in your screenshot.

 

Thanks for being a part of the Community!

-Taylor 

Badge +2

Hi Taylor and thank you for your help!

So for the current year we use: {% today "%Y" as today %} {{ today }}

and for the year of the first purchase the following: 
{{ person|lookup:'First Purchase Date'|default:''|format_date_string|date:'Y'}}

The output of both variables show us only the year (YYYY) of the date.

 

The date format of the first purchase date in the profiles is set up like this: YYYY-MM-DD

 

I hope this provides more clarification.:)

 

Hi there @recirocketteam

 

Welcome to the Community! Happy to help! 

 

The possibility of doing this math between the two variables in a template is a bit complex as it will depend on how the data is passed, the data types, etc. Do you mind sending a screenshot of the event data and event properties to see how they are appearing in your template? 

 

Please be sure not to share sensitive information in your screenshot.

 

Thanks for being a part of the Community!

-Taylor 

 

Userlevel 7
Badge +60

Hi @recirocketteam

 

Thanks for sharing this! 

 

There is a possibility this could work, however, as we can’t help troubleshoot custom code like this, I’d recommend reaching out to a Klaviyo partner, or better yet a Community Champion, to set this up to you!

 

If anyone tries this and finds a way to accomplish this, we’d love for you to share your answer below to help your peers! 

 

-Taylor 

Reply