Is there a simple way to compute the difference between two times (same day), so 11:30 am and 01:20 pm should lead to 110 min (or 1h 50min), for example? I saw the datenumber
package but it only seems to compute day differences (so works on a larger scale). [I didn't include a minimal example as I don't have any elegant way how to start the problem except for (ugly?) string 'divide-and-conquer' approaches]
Okay, I just also discovered datetime
which looks more promising. Nevertheless, I don't see how one can compute differences of time points with this package (or calc
?)
Update
After David's answer, I expanded the MWE to my original example and realized the following Runaway argument
-problem:
\documentclass{article}
\newcommand*{\mystart}{11:30 am}
\newcommand*{\myend}{01:20 pm}
% duration
\def\duration#1#2{%
\the\numexpr(\xduration#2\relax)-(\xduration#1\relax)\relax\ minutes}
\def\xduration#1:#2 #3m#4\relax{%
(#1)*60+#2\if p#3+720 \fi
}
% environment
\newenvironment{tbl}[3]{
\begin{tabular}{ll}
#1 & \duration{#2}{#3}\\
\end{tabular}
}{}
\begin{document}
\begin{tbl}{Duration}{\mystart}{\myend}% Runaway argument? ! File ended while scanning use of \xduration.
%\begin{tbl}{Duration}{11:30 am}{01:20 pm}% works
\end{tbl}
\end{document}
How can this be avoided? [another pair of {}
did not help]
Best Answer
If you want to expand the arguments before parsing, as in the edited MWE: