Convert date in a text field to date format

Hello @EricShulman

I’m referring to [tw5] Re: convert date in a text field to date format:

I’d like to convert my field ‘published’ to a date format with the code provided by @Mark_S:

<$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>

He mentioned:
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.

Can you provide me please the macro?
The mentioned link It's About Time! — TiddlyTools: "Small Tools for Big Ideas!" (tm) is not valid anymore.

Background info: ‘published’ can be a date in the future. This field can be used for sorting instead of ‘created’ or ‘modified’ in TOC etc.

Is there also a way to run the convertion each time, when I start my wiki?

Thanks,
Stefan

The <<convertdate ...>> macro has been replaced by a more powerful and flexible [parsedate[...]] filter that eliminates the need for using $wikify.

Note that all TiddlyTools TW5 add-ons are now published here: https://TiddlyTools.com
and the ParseDate filter is here: https://TiddlyTools.com/#TiddlyTools%2FTime%2FParseDate
Full documentation for the filter is here: https://tiddlytools.com/#TiddlyTools%2FTime%2FInfo

After installing TiddlyTools/Time/ParseDate (and save-and-reload so the new filter operator will be defined), instead of writing:

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

you can just write:

<$action-setfield $field=published-tw $value={{{ [{!!published}parsedate[]] }}} />

which defaults to using the TWCore system datetime format ([UTC]YYYY0MM0DD0hh0mm0ss0XXX)

You can use a tiddler tagged with $:/tags/StartupAction, like this:

<$list filter="[has[published]]">
<$action-setfield $field=published-tw $value={{{ [{!!published}parsedate[]] }}} />
</$list>

enjoy,
-e

1 Like

Hello @EricShulman,

thanks - but what am I doing wrong? Updated field is empty:
update_field_nok.json (6.2 KB)

TiddlyTools/Time/ParseDate is a FILTER… NOT a macro. As such, it should NOT be tagged with $:/tags/Macro, but must have a type field = application/javascript AND module-type field =filteroperator.

The correct way to install this filter operator in your TiddlyWiki is to just drag-and-drop the tiddler directly from https://tiddlytools.com/#TiddlyTools%2FTime%2FParseDate (you can drag the tiddler title). This will ensure that all the fields are properly set as required.

In addition, I note that Stefan/Update "published-tw" and Stefan/Update "published-tw" (Startup) tiddlers specify a datetime format for the parsedate[...] operator:

<$action-setfield $field=published-tw $value={{{ [{!!published}parsedate[YYYY0MM0DD0hh0mm0ss0XXX]] }}} />

However… this may produce incorrect results since it will convert the published datetime to your local time zone instead of setting a TWCore standard timestamp value (which always uses [UTC] time, regardless of your time zone).

To automatically produce the default output format of [UTC]YYYY0MM0DD0hh0mm0ss0XXX you should just use the parsedate[] operator without specifying any datetime format code, like this:

<$action-setfield $field=published-tw $value={{{ [{!!published}parsedate[]] }}} />

-e

@EricShulman thanks a lot, now it is working! :slight_smile:

@EricShulman

One additional thing:
With that code all tiddlers with <$list filter="[has[published]]"> are updated to a TWCore system datetime format to the field ‘published-tw’. :slight_smile:

I have changed the tiddler tagged with $:/tags/StartupAction from

<$list filter="[has[published]]">
<$action-setfield $field=published-tw $value={{{ [{!!published}parsedate[]] }}} />
</$list>

to

<$list filter="[has[published]!has[published-tw]]">
<$action-setfield $field=published-tw $value={{{ [{!!published}parsedate[]] }}} />
</$list>

for not to update my complete wiki with every start.

Actual all tiddlers has ‘modified’ date from today - which is not good :frowning:

Can you provide me please a code for a unique fix to set ‘created’ = ‘modified’ for <$list filter="[has[published]]">?

Thanks
Stefan

I suggest adding $timestamp=no to the $action-setfield, like this:

<$list filter="[has[published]!has[published-tw]]">
<$action-setfield $timestamp=no $field=published-tw $value={{{ [{!!published}parsedate[]] }}} />
</$list>

This will prevent the created and modified fields from being updated when setting the published-tw field.

Also, note that you can shorten the code a bit by using

<$action-setfield $timestamp=no published-tw={{{ [{!!published}parsedate[]] }}} />

which is equivalent to using the separate $field and $value parameters

-e