Oh ok sorry!
So yep tag it with systemConfig and it will become a plugin.
At the moment it is hardwired to look for a field called 'dob' and
'dod' on the tiddler it is called from.
These fields must have dates in the format YYYYMMDD.
How are you planning to use it?
Would you want it to work for the tiddler it is called from or would
you want to give it two dates as arguments? If the latter try the
following (untested) by doing <<age 20071201 20080302>>
The first two lines of the macro set where the date comes from. Don't
be scared to experiment by changing where they come from.
Hope my help was better this time :)
Jon
config.macros.age ={
handler: function(place, macroName, params, wikifier, paramString,
tiddler){
var d1 = params[0];
var d2= params[1];
//var d1 = tiddler.fields["dob"];
//var d2= tiddler.fields["dod"];
if(!d2){
d2 = new Date().convertToLocalYYYYMMDDHHMM();
}
var y1 = parseInt(d1.substr(0,4));
var y2 = parseInt(d2.substr(0,4));
var m1 = parseInt(d1.substr(4,2));
var m2 = parseInt(d2.substr(4,2));
var day1 = parseInt(d1.substr(6,2));
var day2 = parseInt(d2.substr(6,2));
var ageY = y2-y1;
var ageM = m2 - m1;
if(m2 > m1){
ageM = m2 - m1;
}
else if(m2 < m1){
ageM = 12 -(m1- m2);
ageY -=1;
}
var html =ageY + "years";
if(ageM != 0){
html+=" and "+ ageM+" months";
}
jQuery(place).html(html);
}
};