I have a future date, lets call it "lapse" I would like to present the user with the number of days between now an the lapse date.
I was hoping to use dateMath {{dateMath lapse -now format="dd"}} however this is not working. Is there a way to calculate the difference between two dates? Or format a date by the time between when an email was sent and the date in the merge parameter?
Hi David Strom !
We do have something in our docs that may help here: https://support.iterable.com/hc/en-us/articles/360031118392-Handlebars-FAQ-#how-can-i-display-the-number-of-days-since-a-user-signed-up
This specific example checks the days between a user sign up date, but I believe it should function similarly if you change the "signUpDate" to the "lapse". It may require some tinkering on your end to make it work, but if you require additional assistance, don't hesitate to reach out to Support at suppport@iterable.com if you are an ASC for your org.
This will work really well if I could just get dateFormat to convert my ISO date to a Unix or epoch date. If I can do that then the logic would flow pretty easily.
{{#assign open}}{{dateFormat open format="unix"}}{{/assign}}
{{#assign lapse}}{{dateFormat lapse format="unix"}}{{/assign}}
{{#assign difference}}{{math (lapse "-" open)}}{{/assign}}
{{dateFormat difference format="D"}}
Is it possible to format as Unix or Epoch?
Hey David Strom -- I just checked on this for you, and unfortunately it doesn't seem possible to do at this time via handlebars -- this would be a limitation of the handlebars themselves. I know that we do have a helper that looks specifically at timestamp that would automatically output the current time in epoch format, (https://support.iterable.com/hc/en-us/articles/205480365-Personalizing-Templates-with-Handlebars-#current-time-in-epoch-milliseconds-timestamp) but I believe that would be the only native functionality that we have. Apologies if that isn't exactly what you were looking for. Let us know if you have any other questions.
Ok... I built it out as a snippet
{{{ snippet "days_between" futureDate beforeDate }}}
You have to pass in to dates and it will return the time between those dates. Please like and upvote if you use this.
{{#assign "futureDayOfYear"}}{{dateFormat futureDate format="D"}}{{/assign}}
{{#assign "futureYear"}}{{dateFormat futureDate format="yyyy"}}{{/assign}}
{{#assign "futureDaysSinceEpoch"}}{{math (math futureYear "*" 365.25) "+" futureDayOfYear}}{{/assign}}
{{#assign "beforeDayOfYear"}}{{dateFormat beforeDate format="DDD"}}{{/assign}}
{{#assign "beforeYear"}}{{dateFormat beforeDate format="yyyy"}}{{/assign}}
{{#assign "beforeDaysSinceEpoch"}}{{math (math beforeYear "*" 365.25) "+" beforeDayOfYear}}{{/assign}}
{{#assign "difference"}}
{{math futureDaysSinceEpoch "-" beforeDaysSinceEpoch}}
{{/assign}}
{{numberFormat difference "integer" roundingMode="down"}}
Reply
Create a new Iterable Plaza community account
Already have an account? Login
Login to the Iterable Plaza Community
Not a customer? Create an account
Log in to Iterable (SSO)
Iterable customers and employees login/create an accountEnter your E-mail address. We'll send you an e-mail with instructions to reset your password.