How to calculate time left until date+time?

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