Tomorrow's Date from a Template Tag

I use Drafts to write my lesson plans, no surprise, but I love it! I made a video about how I use it here:

Not one to leave well enough alone, I am hoping to use a template tag to pre-load an answer to one of the prompts. I want to use the date tag, but I want it to give me the date for tomorrow (example in the screenshot)

I got the tag formatting from this reference, but I don’t see an option to get tomorrow’s date.

Any advice?

The template tags in and of themselves do not support date math, it requires scripting. If you put the following in a script step at the beginning your your action, it will define a new [[tomorrow]] template tag you can use to insert that date in later steps:

// get tomorrow's date
let tomorrow = Date.today().addDays(1);
// convert it to a formatted date string
let s = strftime(tomorrow, "%m-%d-%Y");
// create the template tag
draft.setTemplateTag("tomorrow", s);
// now use [[tomorrow]] in your prompt step
4 Likes

7 minutes! It only took you 7 minutes to reply with custom code to solve my problem, you sir are amazing!

Thank you for not only making this app, but also being so active and supportive in the forums!

Well, don’t expect that kind of response every time, just caught me over morning coffee. :slight_smile:

5 Likes

No expectation changes, just gratitude and awe! Thanks again!

Can you share the actions?

Sure, this is my first post to the action directory:

https://actions.getdrafts.com/a/1gu

I hope it helps you!

1 Like

Just thought I would say great video.

1 Like

I’m going to look stupid :slight_smile: but this example made why one might create template tags in javascript gel in my mind.

Thank you for your kind words!

I am glad it helped provide that context for you!

Far from looking stupid, but If it helps, I didn’t even know you could define your own tags. So you are one up on me!

1 Like

Hey all;

I’m trying to modify Greg’s code to output today and yesterday’s date as YYYY-MM-DD

Here’s what I tried:

// get tomorrow's date
let tomorrow = Date.today().addDays(1);
// convert it to a formatted date string
let s = strftime(tomorrow, "%Y-%M-%D");
// create the template tag
draft.setTemplateTag("tomorrow", s);
// now use [[tomorrow]] in your prompt step

// get yesterday's date
let yesterday = Date.today().addDays(-1);
// convert it to a formatted date string
let y = strftime(yesterday, "%Y-%M-%D");
// create the template tag
draft.setTemplateTag("yesterday", y);
// now use [[yesterday]] in your prompt step

Today works like a champ, but yesterday outputs something like:

2021-00-05/01/21

I don’t know Javascript, just trying to hack what Greg wrote, so I’m guessing it’s something obvious that I just can’t see…

Thanks for the help.

Your strftime formatting is off.

  • %Y is the 4 digit year
  • %M is the two digit minutes
  • %m is the two digit month
  • %D is a date format equivalent to %m/%d/%y
  • %d is the two digit day

See strftime(3) - Linux manual page for further details on from at tokens.

Brilliant. That did it – Thank You.