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:
-
rehold the regexp pattern for matching a YYYY-MM-DD date string. Note the surrounding parens. This is important for later use within thesplitregexpfilter operator - The $button widget is needed to perform an action that changes tiddler content
-
$listfinds all tiddlers whosetextfield contains a date string -
$action-setfieldsets thestartfield value in each of those tiddlers- The earliest date is extracted from the tiddler
textfield 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 causessplitregexpto 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
-
- The earliest date is extracted from the tiddler
enjoy,
-e
Thank you Eric that worked very well.