Solved

Basic code formatting tips and days_later filter

  • 18 August 2023
  • 6 replies
  • 198 views

Badge +4

Hi,

I’m pretty new to coding with variables within klaviyo. I was wondering if it is possible to use the days_later filter on another date than today. In the documentation it always refer to today. But what if I receive a date in an event like an order date or something.

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

I would like to do somehting like

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


also when coding directly in a klaviyo block is there a way to prevent div, span and other formatting to keep modyfing the code.

 

Thank you!!

icon

Best answer by lagunasolutions 22 August 2023, 21:09

View original

6 replies

Userlevel 7
Badge +44

@lagunasolutions great questions. 

I think this should work, I'm not 100% sure but I would say best thing is to test it out in the editor itself, best way to go about it. I'm not 100% sure because I've not tested it but I think you should be able to get the variable and display it like you want without making it a variable like {{ your_variable|format_date_string||days_later:5|date:'F d, o' }}. You'd need to do some testing around this I think. What's the use case?

As for the div, span and formatting, I haven't found a way that the code does not get updated yet. Seems like there is a code check and modification from Klaviyo end that overrides (y)our code. Most of the times not an issue but not always.

hope this helps!

Omar Lovert // Polaris Growth // Klaviyo Master Platinum Partner

We help with e-commerce growth through CRO, Klaviyo and CVO

Badge +4

Hi @Omar,

 

Thanks for the reply. Quick update on this. Basically we ship 3 days after the order is billed. So I wanted to take the billing date and add 3 days.

I had to try many ways to finally manage to make it work

 

{{ event|lookup:'$next_billing_date'|format_date_string|date:'Y-m-d'|days_later:7 }}

 

Looks like we really need to use the Y-m-d format otherwise it fails. And the days_later filter must be after the date formatting.

Hope this can help someone else

 

have a good day

Badge +2

How can I add 6 hours to a timestamp object?

Badge +4

@noobmarket What is your usecase exactly? Depending on what you need to you could simply break down the date and add to the hour

{% today "%g" as hour %} {{ hour|add:6 }} I guess this would give you the updated hour 

Badge +2

I’d like to get a timestamp that’s like 16 hours from now so that I can pass the timestamp to the countdown timer script.

I’ve been using {{ today|days_later:2}} to add to 2 days to the current time.

But I need a solution to add some specific hours.

Badge +4

@noobmarket I don’t know if that’s possible but I would try to split the datetime into multiple variables (Day,Month,Year,Hour,Minute,Second) and then use the add filter for the hour variable and add 6. Then I would join them all together into a string and then convert it back to datetime using a filter like format_date_string.

 

Hope this helps

Reply