I have dates formatted {yyyy-mm-dd}
. I would like display the time elapsed between the dates in the form Y years, M months. Given the format of the dates, it seems easier to use arithmetic than to manipulate them as dates.
I am trying to call the macro with two date arguments, parsing each one of them. This is the part that is failing, I believe due to the interaction between the two date arguments and their separators. Is there a way to do this within the macro definition, or is it necessary to define another macro to act on each date argument separately?
\documentclass{article}
\newcount\elapsedyears
\newcount\elapsedmonths
\def\elapsedyearsmonths[#1-#2-#3]#4-#5-#6\relax{%
\ifnum#2>#5
\elapsedyears=\numexpr#1-#4
\elapsedmonths=\numexpr#2-#5+1
\else
\elapsedyears=\numexpr#1-#4-1
\elapsedmonths=\numexpr#2-#5+12
\fi
\the\elapsedyears{}years, \the\elapsedmonths{} months
}
\begin{document}
\def\myenddate{2013-10-22}
\def\mystartdate{2010-09-15}
\elapsedmonthsyears{2014-11-06}{2012-02-03}
\elapsedmonthsyears\myenddate\mystartdate
\end{document}
I see now that I will have to create some more conditional statements to pluralise, or not, "year(s)" and "month(s)" also.
Cheers
datetime
package... ;).