I was writing up a will and decided that I wanted to automate certain things. The year is easy to do of course, but I figured there should be something for my age too (I am xx years old). After snooping around a bit and looking at packages which seemed far too complicated (besides, I'm a code minimalist and don't like adding tons of packages), I came up with the following, which I think works fairly well.
Code: Select all
%counters to calculate my age.
%Place `\theage\' in the document where you want your age to appear.
%year counter, month counter, and day counter
\newcounter{dobyear}\setcounter{dobyear}{1985}
\newcounter{dobmonth}\setcounter{dobmonth}{3}
\newcounter{dobday}\setcounter{dobday}{24}
%calculate number of years
\newcounter{age}\setcounter{age}{\the\year}\addtocounter{age}{-\thedobyear}
%condition to test for birthmonth, then birth day.
\ifnum\the\month>\thedobmonth\else%
\ifnum\the\day<\thedobday\addtocounter{age}{-1}\fi\fi