Manipulate date/time created

Hello,

how can date/time created of a tiddler be manipulated by the value mentioned in a user field “date”?

eg:
{{!!created}} = “Tue Aug 24 2021 18:09:03 GMT+0200 (Mitteleuropäische Sommerzeit)”
<$text text={{{ [all[current]get[created]] }}}/> = “20210824160903003”
value of user field “date” = “20220317”

will automatic set created date/time of the tiddler to “20220317160903003”

If the field “date” is not filled - date/time created will be unchanged.

Thanks for feedback
Stefan

Does your data-field always have 8 characters?

Try this: {{{ [{!!created}split[]last[9]join[]addprefix{!!date}] }}}

See the operator docs

Thanks pmario.

Yes, the data-field has always 8 characters.

How is this to configure, that it runs for the whole wiki automatic in the background?

At the moment, the code does only read and show the text. It does not modify any field. There is a widget called action-setfield that can do something. But it will always be user-triggered.

You would need to be more specific why you want to change the created date? Why should it be automatic? … When a tiddler is created it is created automatically.

test-tiddler.json (316 Bytes)

I add to every Tiddler a custom field with a date, when this will be published.
This date can also be in the future and has the format eg. “3. April 2022”
(created and modified doesn’t help)

But this field is not interpreted as a date field. So tried to find a workaround using the created field.

At least, I am searching a way to use it in TOC sorting on that field like
<<toc-selective-expandable ‘Inhalt’ ‘sortan[date]’ >>

as it is possible for created:
<<toc-selective-expandable ‘Inhalt’ ‘sortan[created]’ >>

The goal is to have TOC sorted

  1. by my individual date and
  2. than by Tiddler name

Thanks
Stefan

StS

It is best to save dates as a tiddlywiki standard serial date and use
$view format=“date” template=“YYYY 0MM” or other formats
With the latest release there is also a way to format dates inside filters as well

So create a published-date and set that to the tiddlywiki serial number date eg;
“[UTC]YYYY0MM0DD0hh0mm0ss0XXX”

Perhaps start a new thread if you want to know more about picking dates. But have a look for the pickaday plugin as one option eg Date Picker plugin — based on Pikaday

The date serial is good for searches, ordering, using the days operator and more. The idea is all the other date formats are view formats. The are not practical because to convert them back to a usable date can be done but is fiddly.

1 Like

Can you explain what you mean by “interpreted as a date field”? As far as I am aware, there is nothing special about the created or modified fields…the only difference is in the templates TiddlyWiki typically uses to display them. There’s no reason you can’t use your own field for this, and display its value as a formatted date using something like the $view widget @TW_Tones mentioned.

There is a view template widget thing for dates!!! So it could show a date from the standard yearmonthdayhourminsecmilimicronano format into something more readable… That makes life easier… *sobs quietly and tells himself he WILL read the documentation one day… When there is time… *

Ste,

So let me tell you in the new release you can even format a date inside a filter.

Thanks for feedback.

Let me say it in that way: At the moment, I fill my user field ‘published’ with eg: “11. November 2021” and in TOC
it will be sorted - but not according the date:

<<toc-selective-expandable ‘Inhalt’ ‘sortan[published]’ >>
TOC_sort

An actual workaround is to add manual another user field ‘published_sort’ filled with “20211111”.
Than TOC is proper sorted.
(<<toc-selective-expandable ‘Inhalt’ ‘sortan[published_sort]’ >>)
TOC_sort_ok

How can this be solved in a better way - without 2nd user field or push a button?

Thanks
Stefan

Stefan,
It seems you did miss the file that I did attach in my post: Manipulate date/time created - #4 by pmario

You can download and import it. It basically contains this code.

<$button>
<$action-setfield $tiddler=<<currentTiddler>> $field=created $value={{{ [{!!created}split[]last[9]join[]addprefix{!!date}] }}}/>
Set created dateprefix to {{!!date}}
</$button>

You can write your published field in TiddlyWiki’s format (20211111 – though you may want to add 1200 noon to that, as explained under Timestamp Format here). Then to retain the nice human-readable date format in whatever template is showing that TOC, rather than just transcluding the published field, you would use:

<$view field="created" format="date" template="DD. MMM YYYY"/>

Thanks pmario - missed it - sorry.

This code works fine.
But I’m searching for a better way affecting all tiddlers (having my user field) without a button click.