Generate filename by date

Hello,

I have a document for each Month in this format:

eg:
Test 2023 01.pdf
Test 2023 02.pdf

Test 2023 08.pdf

Actual I use the {{!!title}} to open the file. Every month I have to change the title of the tiddler…

\define filepath_v2() file:///C:/Eigene Dateien/Downloads/{{!!title}}.pdf#view=Fit

<$button tooltip={{{ [<currentTiddler>addprefix[Öffne ]addsuffix[.pdf]] }}}>
<$wikify name="thispath" text=<<filepath_v2>> >
<$action-sendmessage $message="tm-open-external-window" $param=<<thispath>> windowName="_tiddlywiki"  windowFeatures="height=1200, width=1980, top=0, left=0"/>
Open file
</$wikify>
</$button>

I’d like to replace the {{!!title}} in the filepath with the actual date funktionality - like:

Test <<now YYYY>> <<now 0MM>>

grafik

How can that be done?

Thanks, Stefan

G’day Stefan,

Sounds like you are looking for something like this:

{{{ [<now YYYY>] [<now 0MM>] +[join[ ]] }}}

Hi Charlie,
thanks for the good hint :slight_smile: :+1:

This code works:

\define filepath_v2() file:///C:/Eigene Dateien/Downloads/Test {{{ [<now YYYY>] [<now 0MM>] +[join[ ]].pdf }}}.pdf#view=Fit

@Charlie_Veniot the date format is very flexible so the following will do the job

{{{ [<now YYYY0MM>]}}} but for readability we can also to this {{{ [<now YYYY-0MM>] }}} when a set of characters does not get replaced eg YYYY with 2023 it just gets included as a literal as in the -. In these examples there is no spaces in the now parameter.

This means the date format is a good place to concatinate strings around a date format of any kind.

{{{ [<now `Test YYYY-0MM.pdf`>] }}}

can do the whole job @StS

  • In this case I use the single quote to ensure the “now parameter” is interpreted as a single parameter with a space in it.

I’ve been using TiddlyWiki long enough to know that tidbit really well. I don’t know why you’d direct that to me.

I rather appreciated what @StS had done, so much so that I did not want to bring up any of that. I like the approach you took, Stefan. Good stuff.

The forum is not about “who knows what” but what the community knows and can share. Others will come to this topic after a search or reading the title and if they find relavant and related info all the better. I think we should avoid censoring ourselves or others in favor of supporting the comunity.

  • despite this it could be argued I presented an improved method. I addressed you because It was your solution I extended and thought you may appreciate it.
  • there was nothing to indicate you knew what I shared, in fact to the contrary, and I am not a mind reader.

Nah, I didn’t appreciate. Total distraction from the help Stefan was looking for. Part and parcel of the things I don’t like about this forum: lack of OP focus.

Stefan’s filter in the OP was good enough. It did not need fixing. Sometimes, it is good to leave things well enough alone.

Now if you had looked upon the thread and decided: I’m going write a “wiki” article (wiki article: rofl) about “now”, that would have been very cool. Something deserving of a full blown discussion in a dedicated thread.

Sometimes, less is more. Like sticking to the problem/question in the OP without clutter.

I liked Stefan’s approach. It is good stuff.

Small remark:
The single quote " ` " must be replaced by " ’ "

The dash dosen’t fit to the filename I mentioned in the beginning

This code works:

Sorry I did not return you your original example;

Can be replaced with;

{{{ [[file:///C:/Eigene Dateien/Downloads/]] [<now 'Test YYYY-0MM'> [[.pdf#view=Fit]] +[join[]] }}}

Or more like my original answer;

{{{ [<now 'file:///C:/Eigene Dateien/Downloads/YYYY-0MM.pdf#view=Fit'>] }}}

The above works with single quotes.

Now you can use functions;

\function filepath() [<now 'file:///C:/Eigene Dateien/Downloads/YYYY-0MM.pdf#view=Fit'>]

<<filepath>>

{{{ [function[filepath]] }}}
  • You could even pass parameters into your function

Enjoy

Post script:

With URLS and other cases you may want to use the encodeuri[] operator to convert illegal characters eg space to %20 or the reverse decodeuri[] but it is often unnecessary.

works perfect, thanks :slight_smile:

One caveat:

If the literal text portion of the <<now ...>> macro parameter contains any date formatting syntax (e.g., “dd”, “mm”, “am”, “pm”, etc.) then those characters will be substituted with their corresponding date/time values. Thus, if you were to use <<now 'MyTiddlers/YYYY 0MM'>>, “MyTiddlers” would be changed to something like “MyTi01lers” because of the “dd”.

Fortunately, the text portion of your specific example use-case doesn’t contain any date formatting syntax, so it works OK. However, if in the future you were to change that text, you might want to completely avoid this substitution issue by splitting the filtered tranclusion syntax into separate parts, so that the text portion is not included in the <now '...'> macro formatting parameter, like this:

{{{ [[file:///C:/Eigene Dateien/Downloads/]] [<now 'YYYY 0MM`>] [[.pdf#view=Fit]] +[join[]] }}}

-e

Thanks for feedack.

Tested with

\define filepath_v2() {{{ [[file:///C:/Eigene Dateien/Downloads/Test ]] [<now 'YYYY 0MM'>] [[.pdf#view=Fit]] +[join[]] }}}

<<filepath_v2>>

will result in:

grafik

With this code it works:

\define filepath_v2() {{{ [[file:///C:/Eigene Dateien/Downloads/Test ]] [<now 'YYYY 0MM'>] [[.pdf]] +[join[]] }}}.pdf#view=Fit

grafik