Query on how to use list filter with partial field information?

Is there away to filter based on a partial field such as the first four or last four characters of a field (or characters 5 and 6).

I have a field called day with entries in the format of yyyymmdd.

I want to create lists based on years and month, and months and days as well as others possibly.

I have not been able to figure it out so up until now I’ve used a workaround of having extra fields such as year (yyyy), monthnum (mm), Anni-day (mmdd) for example to use for filtering.

I’m looking for ways to make my wiki more efficient though and perhaps reduce the amount of fields I use.

Example of a current filter in use.

<$list filter="[tag[journal]year{!!year}monthnum{!!monthnum}sort[day]]"><$link to={{!!title}}><$view field="title"/></$link>

You can use the search:day:regexp[...] filter operator to find a text pattern within the day field value, like this:

find date (yyyymmdd): <$edit-text field="date"/><br>
<$let re={{{ [[^]] [{!!date}] +[join[]] }}}>
<$list filter="[tag[Journal]search:day:regexp<re>sort[day]]"><$link/></$list>
</$let>

The search uses “^” to find a regexp pattern from the beginning of the field value.

You can enter any number of digits to match; e.g., “2023” to match all dates in 2023, “202305” to match only dates in May 2023, or even “20230516” to match only May 16th, 2023.

You can also use “.” in the pattern for wildcard characters; e.g., “…05” matches all dates in May (any year), “…0516” matches May 16th (any year).

enjoy,
-e

Thanks. The answer looks useful but it’s not quite what I’m looking for but that’s likely as I probably wasn’t clear on how my filter lists are being used.

I am not looking for user interface such as a search box though I’m sure I can adapt this code for use elsewhere.

I have a tiddler for example that lists all the journal entries for the year 2023 and the month of may. It calls a template that has a version of the filter command I posted in my original chat. Another tiddler is looking up all the journal entries of the that particular month and day which are marked as having a significant event on it. e.g. 23rd May.

So for example the May 2023 tiddler for example will need to match it’s day field (or it could be a different field name if that helps) which only has six digits with the first six digits (of eight) of the journal day fields.

The code I provided can be easily adapted for use within a template, without needing a user interface:

In a DayListTemplate tiddler, you could put:

<$list filter="[tag[Journal]search:day:regexp{!!day}sort[day]]"><$link/></$list>

Then, for example, in a tiddler named “May 2023”, create a day field containing ^202305 (i.e., the regexp pattern for days starting with “202305”), and a text field containing {{||DayListTemplate}}.

Similarly, in a tiddler named “Anniversaries on 23rd May”, create a day field containing 0523$ (i.e., the regexp pattern for days ending with “0523”), and a text field containing {{||DayListTemplate}}.

And, in a tiddler named All journals for May, create a day field containing ^....05 (i.e., the regexp pattern for days in month 05 of any year), and a text field containing {{||DayListTemplate}}.

2 Likes

Thanks.

I did try to adapt your earlier code myself but wasn’t getting it right. New code seems to work great.

@Alan_101 Eric has given you an answer however I would just let you know there are multiple ways to address this. With dates in tiddlywikis date stamp format, or part there of the date format is sufficient to extract different parts of a date;

If date-field contains 20230405 ie; YYYY0MM0DD (not the 0 for zero filled)

* {{{ [{!!date-field}format:date[YYYY]] }}}
* {{{ [{!!date-field}format:date[0MM]] }}}
* {{{ [{!!date-field}format: date[0DD]] }}}
* {{{ [{!!date-field}format:date[YYYY0MM]] }}}
* {{{ [{!!date-field}format:date[YYYY0MM]match<now YYYY0MM>] }}} this month?

You can extract a form you want to compare

There are also otherways to test or separate strings within other strings.

1 Like

Thaks TW_Tones. This looks interesting but I’m struggling to understand how to implement it at this time (I’m not a developer and struggle a bit with some of the more advance features).

Currently looking at implementing Eric’s solution but a related stumbling block is viewing partial fields.

In Windows Command Line if I run the command echo %date% I get the result 17/05/2023. If I run echo %date:~6,4% it displays just 2023. Is there similar functionality for viewing fields? My search is not coming up with anything on this.

Currently my anniversary template code looks like this

<$list filter="[tag[otd]search:day:regexp{!!Anniversary}sort[day]]"><$link to={{!!title}}><$view field="year"/></$link>  
<$view field="eventdetails"/><br/>
</$list>

I want to replace the <$view field="year"/> portion of this so I can retire the year field.

If you want to refer to different parts of a date field you can input it to the format: date[format] operator to get it, that’s what I do in my examples.

Although I understand it takes time to get familiar with what I call “TiddlyWiki script” and filters, but it is a great investment in your future.

However you can use the split operator to spit every character from a string and reassemble the ones you want. Just change it to use the variable or field containing the value.

{{{ [[20230405]split[]last[4]first[2]join[]] }}}
  • Here I put a filter inside the {{{ }}} just to make it work on tiddlywiki.com
  • I am extracting the month
  • Have a look at the other operators
  • Note I split and join with empty parameters this spits and joins every character

Here is an example with your date format; to get month

{{{ [[17/05/2023]split[]first[5]last[2]join[]] }}}

To get YYYY

{{{ [[17/05/2023]split[]last[4]join[]] }}}

See also nth and zth operators

<$let day={{{ [{!!date-field}split[]first[2]join[]] }}}
         month={{{ [{!!date-field}split[]first[5]last[2]join[]] }}}
         year={{{ [{!!date-field}split[]last[4]join[]] }}}>

Day: <<day>> Month: <<month>> Year: <<year>>
</$let>

Or with your / delimited date;

<$let day={{{ [{!!date-field}split[/]first[]] }}}
         month={{{ [{!!date-field}split[/]nth[2]] }}}
         year={{{ [{!!date-field}split[/]last[]] }}}>

Day: <<day>> Month: <<month>> Year: <<year>>
</$let>
  • First and last parameters in the operator defaults to 1
1 Like

Thanks TW_Tones

My new code for the anniversay template is now as follows.

 <$list filter="[tag[otd]search:day:regexp{!!Anniversary}!sort[day]]"> <$link to={{!!title}}><$let dispyear={{{ [{!!day}split[]first[4]join[]] }}}><<dispyear>></$let></$link>  
<$view field="eventdetails"/><br/>
</$list> 

I’ve also used the code in a different template that displays the full date in a dd/mm/yyyy order.

<$let dispday={{{ [{!!day}split[]last[2]join[]] }}}
         dispmonth={{{ [{!!day}split[]first[6]last[2]join[]] }}}
         dispyear={{{ [{!!day}split[]first[4]join[]] }}}>

//This entry was written on <<dispday>>/<<dispmonth>>/<<dispyear>>//
</$let>

With changes made from eric I’ve added/ or will add the $ at the end of the Anniversary fields calling the template. I’ve also made an adjustment to the DefaultTiddlers so the right anniversary file comes up on the right day. [contains:Anniversary<now 0MM0DD$>]

Once again, my thanks to the both of you.

I just identified another method to parse dates into different elements, use date format for all the elements you need then use the SetMultipleVariablesWidget or in button or trigger you could use the same parameters in a ActionSetMultipleFieldsWidget

<$setmultiplevariables $names="year month day" $values="[{!!modified}format:date[YYYY 0MM 0DD]enlist-input[]]">

;Year=<<year>> month=<<month>> day=<<day>>
</$setmultiplevariables>
  • The variables will be valid inside the $setmultiplevariables widget
  • The names and values need to match one for one
  • Tip the date field/variable content, needs to be in the required order but can be “truncated” ie YYYY0MM0DD rather than YYYY0MM0DD0hh0mm or the full tiddlywiki serial date/time and still works in the format operator.
  • You can use enlist-input[] or split[ ]
1 Like