# Calculating time difference within datatools foreach

I'm trying to build a table with some calculations from an external file. data.csv:

From,To,Task


I'm using datatool to read the csv and it's foreach to output the data. However I'm stuck when it comes to calculate the time difference 10:00 - 11:00 (=60min). I have the macro \dur but it does not work within foreach -.-

here is my tex code:

\documentclass{article}

\usepackage{datatool}
\usepackage{fp}

\def\dur#1#2{\the\numexpr(\xdur#2\relax)-(\xdur#1\relax)\relax\ }
\def\xdur#1:#2\relax{(#1)*60+#2}

\begin{document}

Here dur works:
\dur{10:00}{13:30} \par

Here dur does not work:
\DTLforeach{data}{\from=From,\to=To}{\from--\to=\dur{\from}{\to} \par}

\end{document}


So my question is how to create a macro to compute the time difference within the foreach. And i'd like also to sum up the result.

(I already succeeded summing up read in values by using fp like this: \DTLforeach{scores}{\score=Score}{\FPeval\result{clip(\result+\score)}}, but I need the duration as varable to pass it in there)

Calling \xdur\from won't work, because TeX doesn't expand tokens when the arguments to \xdur are looked for.

You have to expand the argument before \xdur is expanded. When the times are given explicitly, \expandafter will do nothing, but no harm either.

\begin{filecontents*}{\jobname.csv}
\end{filecontents*}

\documentclass{article}

\usepackage{datatool}

\def\dur#1#2{%
\the\numexpr\expandafter\xdur#2\relax-\expandafter\xdur#1\relax\relax
}
\def\xdur#1:#2\relax{(#1)*60+#2}

\begin{document}

Here dur works:
\dur{10:00}{13:30} \par

Here too:
\DTLforeach{data}{\from=From,\to=To}{\from--\to=\dur{\from}{\to} \par}

\end{document}