Ok, for sake of completion, and for anyone else who might be looking
for this someday, here's what worked for me.  Its a modification of
something Udo B wrote for someone a while back, and FND recently
helped me with the rounding.  So someone with a Date of Birth
2000-01-01 should read as 9.4 years old.

Its a FET that looks at the date of birth which is stored in the title
of a tiddler, and that tiddler has a tag called "Age" (which for
convenience I've also titled the tiddler that contains this FET.:

<<forEachTiddler
where
        'tiddler.tags.contains("Age")'

sortBy
        '(tiddler.title)'

script '

        // Returns the first line of the string
        //
        function getFirstLine(s) {
                var m = s.match(/\s*(.*)/);
                return m != null && m.length >= 1 ? m[1] : "";
        }

        // Returns the number of days between two dates.
        //
        // Only the year,month and day of the dates are considered.
        //
        // if date2 < date1 the result will be negative.
        //
        function getDaysBetween(date1, date2) {
                date1 = new 
Date(date1.getFullYear(),date1.getMonth(),date1.getDate
());
                date2 = new 
Date(date2.getFullYear(),date2.getMonth(),date2.getDate
());
                return ((date2.getTime()-date1)/86400000).toFixed();
        }

        // Returns the date given by the string s
        //
        // @param s                     String of format YYYY-MM-DD ("-" may be 
any char)
        // @param defaultValue  returned when s is not a valid date.
        //
        // @return a Date object representing the given date.
        //
        function parseDate(s, defaultValue) {
                try {
                        return new Date(parseInt(s.substr(0,4),10),
                                        parseInt(s.substr(5,2),10)-1,
                                        parseInt(s.substr(8,2),10));
                } catch(e) {
                        return defaultValue;
                }
        }

        function getYearsLeftText(tiddler) {
                return Math.round(((getDaysBetween(new Date(),parseDate
(tiddler.title, new Date())))/-365)*10)/10+" years old";
        }
'

write
        'getYearsLeftText(tiddler)+"\n"'
>>


-Dave
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/TiddlyWiki?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to