The same result can be obtained without any package:
\makeatletter
\newcommand\ifafter[3]{%
\ifnum\the\year\two@digits\month\two@digits\day >
\numexpr#1\two@digits{#2}\two@digits{#3}\relax
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi}
\makeatother
We can also encode the date as "year*10000+month*100+day", so the test can be
\makeatletter
\newcommand\ifafter[3]{%
\ifnum\numexpr\year*10000+\month*100+\day\relax
>\numexpr#1*10000+#2*100+#3\relax
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi}
\makeatother
Or, with etoolbox
and datetime
, without an auxiliary counter:
\newcommand{\ifafter}[5]{%
\ifnumgreater
{\the\year\twodigit{\the\month}\twodigit{\the\day}}
{#1\twodigit{#2}\twodigit{#3}}
{#4}
{#5}%
}
The relevant thing here is that TeX continues to expand tokens when it is looking for a number. My definitions allow also
\ifafter{2012}{1}{16}{Yes, it is after Jan. 16, 2012.}{No, it is not after Jan. 16, 2012.}
Your macro would be unsuccessful on Jan. 17, 2012 with
\ifafter{2012}{2}{1}{after}{not after}
as the comparison would be between 20120117 and 201221. Using \twodigit
both for today's date and the user input guarantees correct result even when the user is lazy.
And the LaTeX3 version:
\usepackage{xparse}
\ExplSyntaxOn
\DeclareExpandableDocumentCommand{\ifafter}{ m m m }
{
\int_compare:nTF
{ \year*10000+\month*100+\day > #1*10000+#2*100+#3 }
}
\ExplSyntaxOff