[tw5] Re: convert date in a text field to date format

@ Eric

Just tried

<<convertdate from:“7. April 2021” to:"[UTC]YYYY0MM0DD0hh0mm0ss0XXX">>

and got a hard RSOE (“from” not defined). I think the arguments need to be tweaked in the macro.

HTH

Format T.MMMM JJJJ ?

Surely you mean “0DD. MMM YYYY”

In this case you would parse this date to extract the DD, MMM and YYYY as separate values, convert from MMM to a month number with a 12 month table, then re-assemble them into a tiddlywiki date/time string. I suggest 1200 or 12 noon as the time, otherwise zero fill seconds and milliseconds.

eg D all before “.”,
Month split[ ]nth[2]
Year split[ ]nth[3] or last[]

Regrds
Tones

That’s a good point. I imagine S2’s source application is using some local formatting code (e.g. German, Dutch). So the format would have to be altered to the ISO 8601 standard for use in javascript (and probably all of TW) when specifying input. But, presumably the output would automatically conform to the browser’s locale string ??

OOPS! I had originally used “date” and “format” as the parameter names, but then I decided to change to using “from” and “to”. Unfortunately, the arguments in the macro function declaration were still using “date” and “format”, but internally, the macro code referenced “from” and “to” as intended. I’ve corrected the arguments in the macro function declaration and posted an update here:

https://tiddlytools.com/timer.html#TiddlyTools%2FTime%2FConvertDate

Thanks,
-e

Hello,

thanks for all input and effort.
It looks like it is not so easy…

As I wrote, I use the text field ‘publish’ to add a date. (date modified or created will not help me)

This date can also be in the future.
Format is T. MMMM JJJJ - (eg. 7. April 2021 or 13. August 2021) – this is the long date in German (like “DDth MMM YYYY”)

‘published’ is also shown in TOC:

TOC.png

Now asked for a way to sort TOC on ‘published’ instead of Tiddler title.

The output should still be “DDth MMM YYYY”

Thanks
Stefan

So what you really need is a filter operator that can do the conversion and be used inside a sortsub operator. @Eric ?

If you’re willing to use an “update” button, one solution would be a button that creates “published-tw” (date in TW format) fields for any tiddler that has a “published” field. Then you could have the TOC sort on the published-tw field. You would have to remember to periodically perform the “update” whenever you had data changes. This two-step approach makes certain activities in TW much easier to handle.

So the code to update the field might look like:

<$button>Update Publication Dates
<$list filter="[has[published]]">
<$wikify text="""<$macrocall $name=convertdate from={{!!published}} to="[UTC]YYYY0MM0DD0hh0mm0ss0XXX" />""" name=result >
<$action-setfield $field=published-tw $value=<> />
</$wikify>
</$list>
</$button>

Be sure to make a backup before trying this of course. Also, this assumes that you have the latest version of Eric’s converdate macro installed.

Mark, thanks for feedback.

The added ‘published-tw’ field is empty - no values:

So, did you add Eric’s macro to your TW and verify it works? That would be the first step in trouble-shooting. Remember, after loading the convertdate macro, you have to save and reload your TW file.

It worked for me without problem:

Mark,
yes, Eric’s macro is there, tagged as ’ $:/tags/Macro’.

I downloaded an emty Wiki - ‘published-tw’ field will also not be filled.

To use the “Update Publication Dates” button is a workaround but not the best solution.

I miss a system ‘date’ field, like ‘created’ or ‘modified’.

When this field is filled with format “DDth MMM YYYY” than it is a valid date of “[UTC]YYYY0MM0DD0hh0mm0ss0XXX”

BTW: in $:/ControlPanel/Title of new journal tiddlers is the same format (DDth MMM YYYY) defined

One solution can be:

  1. Adding a text field (eg ‘published’)

  2. Define, that this field is a date/time field

  3. The value of the ‘published’ field will be converted to “[UTC]YYYY0MM0DD0hh0mm0ss0XXX” and is available as system ‘date’ field.

Than it can also be used in TOC like
<toc-selective-expandable ‘Inhalt’ ‘sortan[date]’ >>

as it is possible for created:

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

Regards
Stefan