Computing Days Until with Emacs
08 Apr 2026 Charles Choi
A recent Mastodon post showing the days until the next U.S. election got me to wonder, “how can I compute that in Emacs?” Turns out, this is trivial with the Org mode function org-time-stamp-to-now doing the timestamp computation for you.
We can wrap org-time-stamp-to-now in an internal function cc/--days-until that generates a formatted string of the days until a target date.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
From there we can then start defining commands that use cc/--days-until. The command cc/days-until shown below will prompt you with a date picker to enter a date. Note that you can enter a date value (e.g. “Dec 25, 2026”) in the mini-buffer prompt for org-read-date.
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
Going back to the original motivator for this post, here’s an implementation of days until the next two major U.S. election dates with the command cc/days-until-voting.
1 2 3 4 5 6 7 8 9 10 11 12 | |
The result of M-x cc/days-until-voting as of 8 April 2026 is:
209 days until 2026 midterms, 944 days until 2028 presidential election
It’s so human to want to know how long it’s going to take. Feel free to build your own countdown clocks using the code above. May your journey to whatever you plan be a happy one!