Age calculation


(Paul) #1

Is it possible (available) - and if yes how - may I automate the calculation of a person’s age by seizing its birth date ?
Thanks for your answer.

François


(Mark Anderson) #2

Assuming the birthdate is in $MyDate, the number of whole years (age) is returned as a number by this action code:

$MyNumber=years($MyDate,date("today"));

(Paul) #3

Thank you very much for your answer.
However I do not reach the desired result.
I have created a “new user attribute”, of type “number” and written
$MyString=“24.03.1834”;
$MyDate=date($MyString);
$MyNumber=years($MyDate,date(“today”));
in its “Description”, but probably it’s not what is needed, while the return number is wrong.
Could you help me a bit more ?

Cordially yours,
François


(Mark Anderson) #4

For me, $MyNumber is 184 (years). The only amendment I made to your code was to ensure all the double quotes were straight " and not ‘curly’ or .

Your first two lines can be written as one:

$MyDate=date("24.03.1834");

Interestingly, on my UK locale system Tinderbox still correctly parsed out 24 March 1834 as the date, even though in my locale that is normally written 23/03/1834.

I ran the code as a edict, but you could use a rule. If you are looking at the result as a ket attribute of the note being acted on, you may need to de-reselect the note to refresh the KAs.

Here is the result I see:

date-test1


(Paul) #5

It’s OK !
I got it now
Thank you very much Mark !

Sincerely yours.

François