Find the earliest date in each of a selection of tiddler's text field

My tiddlers each have one or many dates in the format YYYY-MM-DD in their text field. For each tiddler i want to find the earliest of those dates and place it in that tiddlers ‘start’ field which already exists. How can this be done?

Give this a try:

<$let re="(\d{4}-\d{2}-\d{2})">
<$button> extract start dates
<$list filter="[all[]search:text:regexp<re>]">
<$action-setfield start={{{ [{!!text}splitregexp<re>search:title:regexp<re>sort[]first[]] }}}/>
</$list>
</$button>

Notes:

  • re hold the regexp pattern for matching a YYYY-MM-DD date string. Note the surrounding parens. This is important for later use within the splitregexp filter operator
  • The $button widget is needed to perform an action that changes tiddler content
  • $list finds all tiddlers whose text field contains a date string
  • $action-setfield sets the start field value in each of those tiddlers
    • The earliest date is extracted from the tiddler text field using a filtered transclusion:
      • splitregexp<re> splits the text into separate parts where each date string occurs. Because the regexp pattern is enclosed in parens, it is a “capture group”, which causes splitregexp to retain those date strings in the resulting list of items. Otherwise, only the surrounding text items would be retained and the date strings would be discarded.
      • search:title:regexp<re> keeps only those parts that are actually date strings
      • sort[] sorts the date strings in ascending order
      • first[] then retains only the first date string, which will be the earliest date found in the text

enjoy,
-e

Thank you Eric that worked very well.