Solved

Countdown Timer Formats

  • 13 June 2023
  • 4 replies
  • 398 views

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? 

icon

Best answer by Felix 14 June 2023, 08:59

View original

4 replies

Userlevel 4

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

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

@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!

Userlevel 4

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