While we’re at it …
Days until …, done right
This is a little longer, but it will check if it’s already past the date for this year, and show the difference in days until the same date next year!
This is ideal for recurring events like Christmas, Birthdays, Anniversaries, etc.
To make things simple, I use JS to set a variable at the beginning. This allows editing just one place instead of many.
<!-- Days until any "MM-DD" date this year/next year -->
<%+* let edate = moment("12-24", "MM-DD"); let from = moment().startOf('day'); edate.diff(from, "days") >= 0 ? tR += edate.diff(from, "days") : tR += edate.add(1, "year").diff(from, "days") %>
Days until …, plus “It’s Today!”
Same as above, but will display “It’s today!” instead of a plain old zero if we happen to be on the date.
<!-- Days until any "MM-DD" date this year/next year with "TODAY" -->
<%+* let edate = moment("12-24", "MM-DD"); let from = moment().startOf('day'); edate.diff(from, "days") >= 0 ? edate.diff(from, "days") == 0 ? tR += "It’s today!" : tR += edate.diff(from, "days") : tR += edate.add(1, "year").diff(from, "days") %>
Enjoy! (And never again worry about “days to Christmas” being -2!)