Dave, I marked it complete for you, however I am playing with wikitext solutions to support dates, and update the documentation.
Once again my frustration that we can't format variables using the viewWidget or something else. Because to place a value in a tiddler or field needs a trigger, and the viewWidget does not accept variables as its input. Starting with these simple macros. Note you can wrap them in a set variable of date-field. There main function was to pull part of a date time from a date-field, rather than using the verbose view Widget. Such partial dates could be passed into other macros using the macrocall widget. \define YYYY(date-field) <$set name=date-field value=<<date-field>> emptyValue="$date-field$"> <$set name=date-field value=<<date-field>> emptyValue="created"> <$view field=<<date-field>> format="date" template="YYYY"/> </$set></$set> \end \define 0MM(fieldname) <$set name=date-field value=<<date-field>> emptyValue="$date-field$"> <$set name=date-field value=<<date-field>> emptyValue="created"> <$view field="$fieldname$" format="date" template="0MM"/> </$set></$set> \end \define 0DD(fieldname) <$set name=date-field value=<<date-field>> emptyValue="$date-field$"> <$set name=date-field value=<<date-field>> emptyValue="created"> <$view field="$fieldname$" format="date" template="0DD"/> </$set></$set> \end \define 0hh(fieldname) <$set name=date-field value=<<date-field>> emptyValue="$date-field$"> <$set name=date-field value=<<date-field>> emptyValue="created"> <$view field="$fieldname$" format="date" template="0hh"/> </$set></$set> \end \define 0mm(fieldname) <$set name=date-field value=<<date-field>> emptyValue="$date-field$"> <$set name=date-field value=<<date-field>> emptyValue="created"> <$view field="$fieldname$" format="date" template="0mm"/> </$set></$set> \end \define 0ss(fieldname) <$set name=date-field value=<<date-field>> emptyValue="$date-field$"> <$set name=date-field value=<<date-field>> emptyValue="created"> <$view field="$fieldname$" format="date" template="0ss"/> </$set></$set> \end \define 0XXX(fieldname) <$set name=date-field value=<<date-field>> emptyValue="$date-field$"> <$set name=date-field value=<<date-field>> emptyValue="created"> <$view field="$fieldname$" format="date" template="0XXX"/> </$set></$set> \end You can wrap the macros in a set widget setting date-field to the fieldname you want to refer to. Also this is a Work in progress Date time macro Syntax<<date-time [template] [date-field]>><$macrocall $name=date-time template=[value] date-field=[value]>Where template, date-field or value are optionaldate-field defaults to created or uses a variable 'date-field' or the value provided in the macro executiontemplate defaults to Now! YYYY-0MM-0DD 0hh:0mm:0ss Local time, Set in $:/config/now-format <https://tiddlywiki.com/#%24%3A%2Fconfig%2Fnow-format>template can be set any valid DateFormat <https://tiddlywiki.com/#DateFormat>Examples of using the date time macro<<date-time>> > true *Now!*<<date-time "Year made YYYY">> > Year made 2019 *Tiddler created date used*<<date-time "Hour changed 0hh" modified>> > Hour changed 12 *Tiddler modified date used* <$set name-date-field value=my-date-field> code <<YYYY>> <<0MM>> and more code </$set> The code I am working on another parameter driven one (almost complete) \define date-time(template date-field) <$set name=template value="$template$" emptyValue=<$macrocall $name=now format={{$:/config/now-format}}> > <$set name=date-field value=<<date-field>> emptyValue="$date-field$"> <$set name=date-field value=<<date-field>> emptyValue="created"> <$macrocall $name=return-date-time template=<<template>>/> </$set></$set></$set> \end \define return-date-time(template) <$view field=<<date-field>> format="date" template="$template$"/> \end Regards Tony On Monday, December 2, 2019 at 11:30:43 AM UTC+11, Dave wrote: > > Nevermind - I figured it out. this is what ended up working (thanks to > your comment about the months) > > /*\ > title: $:/inmysocks/macros/day-diff2.js > type: application/javascript > module-type: macro > > Takes two dates and returns their difference in days > > \*/ > (function(){ > > /*jslint node: true, browser: true */ > /*global $tw: false */ > "use strict"; > > /* > Information about this macro > */ > > exports.name = "day-diff2"; > > exports.params = [ > {name: "duedate"} > ]; > > /* > Run the macro > */ > exports.run = function(duedate) { > //Make each date object. > var date1 = new Date(); > var d = duedate; > var year = d.substring(0, 4); > var month = d.substring(4, 6); > var month2 = month - 1; > var day = d.substring(6, 8); > var date2 = new Date(year, month2, day); > > > > //Find difference in milliseconds. > var elapsed = date2.getTime()-date1.getTime(); > > //Number of milliseconds in a day. > var dayMS = 86400000; > > //Convert milliseconds to year months and days > var days_diff = Math.floor(elapsed/dayMS); > var result = days_diff; > > return result; > }; > > })(); > > > -- You received this message because you are subscribed to the Google Groups "TiddlyWiki" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/02ec80c3-176d-4ba3-82a6-94474e1998e6%40googlegroups.com.

