Skip to main content
Contributor I
Nov 19, 2024 2:56 PM UTC
Solved

Calculate number of days until date in email template

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.
    retention
    retentionAnswer
    2025 Champion
    Nov 23, 2024 12:44 AM UTC

    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

    3 replies

    Taylor Tarpley
    Community Manager
    Community Manager
    Nov 22, 2024 11:26 PM UTC

    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
    Nov 23, 2024 12:44 AM UTC

    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
    Nov 25, 2024 12:31 PM UTC

    Hey Jospeh ​@retention,

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