Append Creation Date as Header

How can I append the creation date of a Draft to the top of the draft as a header?

There is an action to insert the creation date into a note, but it does it at the end, not at the beginning, and not as a header. There is also an answer to a previous question I had about prepending, but that is a script and doesn’t seem to take template tags. But somehow I can’t figure out how to make these two work together!

(PS: My goal is to import drafts to DayOne. What I would really like to do is to set the creation date in DayOne to the creation day in Drafts, but it seems that the URL schemes can’t do that, so the best second option is to simply add the date as a header…)

I’m going to assume by ‘header’ you mean a Markdown/HTML heading. On that basis, this action should prefix the current draft with it’s creation date (I’ve set it to format as ‘YYYY-MM-DD’) as a level 1 heading on the first line.

It utilises a single script step as follows:

draft.content = "# " + draft.processTemplate("[[created|%Y-%m-%d]]\n[[draft]]");

The content of the draft is set and updated based on prepending the header hash symbol, and then processing some template tags for the creation date (formatted as a date stamp, described above), and the current draft content, with a new line between them.

Just amend it to suit your precise format needs and hopefully you’ll be good to go.

1 Like