6

This is a follow up to TeX capacity exceeded while parsing a date string

I want to compare two dates, say today's date and a due date. I have the due date information stored (as number strings) in macros \dueday, \duemonth, and \duemonth. I use the following, from etoolbox package:

\newcommand{\dueday}{6}
\newcommand{\duemonth}{5} % May
\newcommand{\dueyear}{2012}

\ifboolexpr{
    (test {\ifnumcomp{\dueyear}{>}{\year}})
    or (test {\ifnumcomp{\dueyear}{=}{\year}} and test {\ifnumcomp{\duemonth}{>}{\month}})
    or (test {\ifnumcomp{\dueyear}{=}{\year}} and test {\ifnumcomp{\duemonth}{=}{\month}} and test {\ifnumcomp{\dueday}{>}{\day}})
    }
    {Not due yet}
    {Due immediately}

which does work, but I'm looking for a TeX-based solution that, perhaps, can do this more efficiently and without having to use etoolbox.

1
  • You may want to try \pdfstrcmp. May 6, 2012 at 19:21

1 Answer 1

7

This is doable using a series of pure number (\ifnum) tests, where the boolean logic is indicated by an 'outer' test which uses only 0/1:

\def\dueday{6}
\def\duemonth{5} % May
\def\dueyear{2012}

\def\notdue{Not due yet}
\def\duenow{Due immediately}

\ifnum
  \ifnum\dueyear>\year
    0 %
  \else
    \ifnum\duemonth>\month
      0 %
    \else
      \ifnum\dueday>\day
        0 %
      \else
        1 %
      \fi  
    \fi
  \fi
  > 0 %
  \expandafter\duenow
\else
  \expandafter\notdue
\fi

\bye
1
  • 1
    A pure TeX-based approach, so I've used plain TeX, hence the \bye.
    – Joseph Wright
    May 6, 2012 at 19:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .