JavaScript TextExpander Date / Time Formatting

JavaScript Dates

TextExpander comes with broad date and time format support, but it may not have everything you want. Sometimes, we solve that by adding features. Other times, we can lean on TextExpander’s scripting support.

Some users have asked for ordinal date (1st, 2nd, 3rd, …13th …31st) support. Here’s how to leverage a popular JavaScript library to make that work today.

Important: If you’re on a Mac, please update to TextExpander 6.2.3, as it has an important drawing performance fix to accommodate very large snippets.

The first part of adding ordinal date support is to make a snippet to hold the popular Moment.js JavaScript library:

  1. Make a new snippet
  2. Set its Content: type to JavaScript (using the popup above the snippet editor)
  3. Set the abbreviation for your new snippet to: ,,momentjs
  4. Open this link with your web browser: http://momentjs.com/downloads/moment.min.js
  5. Click in the content
  6. Choose Edit -> Select All (from the menu bar)
  7. Choose Edit -> Copy
  8. Click in your new snippet content in TextExpander
  9. Choose Edit -> Paste

The next part of adding ordinal date support is to create a snippet which includes and uses the Moment.js library:

  1. Make a new snippet
  2. Set its Content: type to JavaScript (using the popup above the snippet editor)
  3. Set the abbreviation for your new snippet to: ,,nthday
  4. Copy and paste this into the snippet content:
%snippet:,,momentjs%

moment().format('Do');

(If you didn’t copy and paste, please note that’s a lowercase letter O above.)

Finally, use %snippet:,,nthday% as part of your date formatting, for example:

%A, %B %snippet:,,nthday% %Y

…which expands to:

Thursday, October 19th 2017

TextExpander’s JavaScript snippets work cross-platform, so this snippet works on all your devices: Macs, Windows PCs, iPads, and iPhones.

For extra credit, you can explore additional Moment.js format options you can use in place of ‘Do’ above.

Keep an eye out for more tips like this on Twitter and Google+.