Skip to main content
Contributor I
November 19, 2024
Solved

Calculate number of days until date in email template

  • November 19, 2024
  • 3 replies
  • 162 views

Hi

We are creating a email template to reminder customers to use their coupon / voucher. We send through a voucher expiry date as part of the event in UTC format

{{ event|lookup:'Coupon Expiry }}

I like to include in my email a reminder to customers to let them know they have XX days left to use their voucher based on Coupon Expiry Date - Time Now

Like: Your voucher expires in 5 days

Can this be calculated as part of the email email formatting in Klaviyo?

Thanks!

    This topic has been closed for replies.
    Best answer by retention

    Hi ​@jonoroy,

    You can try the “timeuntil” filter.  Just make sure to cast your expiry date string as a date object, I’m using the “format_date_string” filter to do this. If you don’t use a specified date for the timeuntil filter, it implies that it is comparing to the time now.

    Roughly, this should work:

    {{ event|lookup:'Coupon Expiry’|format_date_string|timeuntil }}

    You may have to debug it a bit to make it work.

    3 replies

    Taylor Tarpley
    Community Manager
    Community Manager
    November 22, 2024

    Hi there ​@jonoroy

     

    Thanks for sharing your question with the Community! 

     

    This should be possible, can you share what integration owns this coupon? This will inform how you configure the code to show the expiration date.

     

    Thanks for participating in the Community!

    -Taylor 

    retention
    Partner - Platinum
    retentionAnswer
    2025 Champion
    November 23, 2024

    Hi ​@jonoroy,

    You can try the “timeuntil” filter.  Just make sure to cast your expiry date string as a date object, I’m using the “format_date_string” filter to do this. If you don’t use a specified date for the timeuntil filter, it implies that it is comparing to the time now.

    Roughly, this should work:

    {{ event|lookup:'Coupon Expiry’|format_date_string|timeuntil }}

    You may have to debug it a bit to make it work.

    Joseph Hsieh // retentioncommerce.com // X: @retention
    jonoroyAuthor
    Contributor I
    November 25, 2024

    Hey Jospeh ​@retention,

    Thanks so much for this, that worked like a treat!