How to calculate time left until date+time?

How do I enter a formula that will automatically calculate the time left until specified time and date?

For example:
Hello customer,

Our store will re-open on Monday, February 1st at 9:00am.

Countdown timer: {INSERT FORMULA HERE (for 16 hours and 13 days)} left to go!

Hey Bester,

Good question. This is pretty easy with just days or hours, but gets a little more tricky when it's both days and hours. Here's one that I created that will always assume a 9am reopening time. I wonder if anyone else has a more elegant approach than this:

Our store will reopen on {formdate: YYYY-MM-DD; default={time: YYYY-MM-DD; shift=+2D}; name=reopen} at 9:00am. That's only {if: diffcalc>=24}{=remainingdays}{if: remainingdays>1} days{else} day{endif} and {=remaininghours} hours away!{else}{=diffcalc} hours away!{endif: trim=right}
{note: trim=yes}
{diffcalc=datetimediff({time: YYYY-MM-DD HH:mm:ss}, {time: YYYY-MM-DD HH:mm:ss; at={=reopen} 09:00:00; pattern=YYYY-MM-DD HH:mm:ss},"h")}{remainingdays=round({=diffcalc}/24)-1}{remaininghours=remainder({=diffcalc},24)}{endnote: trim=yes}

1 Like

Oh wow, thank you so much!! This was very helpful :heart_eyes:

Where can I find these hidden commands called "datetimediff" and "remainder"? Do I need a special subscription for them?

Those are all documented in our Formula Reference here: Text Blaze | Formula Reference

Sorry if this is a noob question but is there a way to change the formatting to MMMM Do, YYYY?

Not a noob question, time formatting and time calculation can be surprisingly tough.

To update that, I needed to change the format both in the date selector AND in the formula that evaluated the difference between the two times. Here's an updated version:

Our store will reopen on {formdate: MMMM Do, YYYY; default={time: YYYY-MM-DD; shift=+2D}; name=reopen} at 9:00am. That's only {if: diffcalc>=24}{=remainingdays}{if: remainingdays>1} days{else} day{endif} and {=remaininghours} hours away!{else}{=diffcalc} hours away!{endif: trim=right}
{note: trim=yes}
{diffcalc=datetimediff({time: YYYY-MM-DD HH:mm:ss}, {time: YYYY-MM-DD HH:mm:ss; at={=reopen} 09:00:00; pattern=MMMM Do, YYYY HH:mm:ss},"h")}{remainingdays=round({=diffcalc}/24)-1}{remaininghours=remainder({=diffcalc},24)}{endnote: trim=yes}

The preview in the community will still show it in the other format but when it's actually inserted upon snippet use, it'll use the format you requested.

Awesome!! This is perfect, exactly what I was looking for. Thank you so much!