Calculate Next Monday with TextExpander

I consume a lot of information and save the best pieces to my notes in Roam. When I see something I might want to include in my upcoming newsletter I'll give it the tag #[[Newsletter mm/dd/yyyy]] where the date is whatever this coming Monday is.

This way when it's time to write my newsletter I already have a bunch of notes ready for me to choose from.

Well having to figure out what next Monday's date is over and over again started getting cumbersome.

Any time I find myself doing something multiple times I like to find a way to automate it.

So I created a macro for TextExpander (one of my favorite productivity tools) that will automatically create my tag for me whenever I need it.

Now all I have to do is type in .mon and bam my tag fills out and always has this coming Monday filed in.

If you want to do the same just create a new TextExpander snippet.

Choose "Javascript" as the content type.

And then paste the following code in:

function nextDate() {
  var d = new Date();
  d.setDate(d.getDate() + ((7-d.getDay())%7+1) % d.getDay()); //grabs next monday but returns today if today is monday

  var dateStr = d.getDate().toString(); //get day of month
  var monthStr = d.getMonth() + 1; //increment 1 because it is zero index based at starts at 0
  monthStr = monthStr.toString();  //now convert into string
  var yearStr = d.getFullYear().toString();
  var tagStr = "#[[Newsletter " + monthStr + "/" + dateStr + "/" + yearStr + "]]";

  return tagStr;
}

nextDate();

I highlighted the parts that are unique to my use case in orange. You can the extra text I added (e.g. remove + "/") or add your own (e.g. + "hello").

I hope that helps!

Did you enjoy this?

If so you might want to check out my newsletter. Get my best, most actionable insights on growth, productivity, automation, psychology and life delivered to your inbox 1x every other week. Guaranteed to be totally gangster.

Join Newsletter
Top