substring right() function to operate on a field

33 views
Skip to first unread message

François Godard

unread,
Jan 9, 2018, 4:49:37 PM1/9/18
to TiddlyWiki
Hi,

So here is my need 
I have a date field (lets call it: "myDate") that is not formated: values can be "12-02-2015" , "Dec 2016", "Q3 2017" or "2018"
I want to extract the year for display and sorting purposes.

so I usually write right(myDate,4)

now this does not seem to be core. So look on this group i found this post about substring using a javascript macro

This is close enough , for the substring part. If I want to operate on the title of the tiddler , I can modify the code as per below (tested it works well

[...]
exports.name = "substr";
exports.params = [
                              {name: "size",default:"0"},
]; 
/*
Run the macro
*/
exports.run = function(size) {

var tiddlertitle= this.getVariable("currentTiddler");


     return tiddlertitle.substring(tiddlertitle.length-size);
[...]


And this works well on the title , but I would like to reach the myDate field

Am I going in the right direction ? What would be the syntax ? I could not find tips on this
Thanks for your kind help here
Francois
Reply all
Reply to author
Forward
0 new messages