Skip to main content
Solved

Countdown Timer Formats


I am looking to build a timer that I can plug into the body copy of an email. I intended to use the native countdown timer in the CIO docs, but the code doesn’t seem to be formatted to anything other than a banner. 

Here is the use case I am looking for “Your promo expires in x days”. 

Can anyone give me a hand on how I can get this functionality while not using a third party? 

Best answer by Felix

Hey Majormase,

I also tried to format the countdown, but it seems like there are some limitation in case you “embed” in into text. Also I can’t get rid of you “d” after the number.

My suggestions would be that you calculate the days with liquid without the countdown tag. The donwside of this is, that the number will not change once the email is sent out - it will stay static:

{% capture end_date %}1689310355{% endcapture %}

{% capture start_date %}{{ 'now' | date: '%s' }}{% endcapture %}

 

Your promotion expires in {{ end_date | minus: start_date | date: '%d' }} days

 

Hope that helps,
Felix

View original
Did this topic help you find an answer to your question?

4 replies

Felix
  • Novice
  • 223 replies
  • Answer
  • June 14, 2023

Hey Majormase,

I also tried to format the countdown, but it seems like there are some limitation in case you “embed” in into text. Also I can’t get rid of you “d” after the number.

My suggestions would be that you calculate the days with liquid without the countdown tag. The donwside of this is, that the number will not change once the email is sent out - it will stay static:

{% capture end_date %}1689310355{% endcapture %}

{% capture start_date %}{{ 'now' | date: '%s' }}{% endcapture %}

 

Your promotion expires in {{ end_date | minus: start_date | date: '%d' }} days

 

Hope that helps,
Felix


  • Author
  • Novice
  • 4 replies
  • June 14, 2023

Wow! That works perfectly! Thank you so much! CIO should add you to the payroll for that one. 


  • Author
  • Novice
  • 4 replies
  • June 14, 2023

@Felix How do I adjust the date within the block? I see “1689310355” within the block, but I am unfamiliar with that date format. Thank you!


Felix
  • Novice
  • 223 replies
  • June 15, 2023

Hey Majormase,

thanks for that comment there 😀 Doing my best.

CIO uses Unix timestamps. This format represents the seconds passed since 01/01/1970. This allows you to easily do math operations with seconds, hours, days, months and years. You can use this website to find out which UNIX timestamp refers to your date & time.

 

In case the promotions expires always X days after you send out the email, you can also leave it as a static value. If you store the expiration date in a separate attribute in the person’s profile, you can simply replace “end_date” with your attribute in {{ end_date | minus: start_date | date: '%d' }}.

 

Best,

Felix

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings