[texhax] Time calculation within LaTeX

ekmath at asianetindia.com ekmath at asianetindia.com
Mon Feb 11 09:24:01 CET 2008



The "fp" package gives a neat solution to your problem

   \usepackage{fp}

   \def\timediffcalc(#1:#2-#3:#4){%
     \FPeval\btm{#1 * 60 + #2}
     \FPeval\etm{#3 * 60 + #4}
     \FPeval\adtm{\etm - \btm}
     \FPeval\cdtm{1440 + \etm - \btm}
     \FPifpos\adtm
       \FPset\dtm{\adtm}
     \else
       \FPset\dtm{\cdtm}
     \fi
     \FPeval\dth{\dtm / 60}
     \FPtrunc\dthtrunc\dth2}

   \def\timediffprn(#1:#2-#3:#4){%
    \timediffcalc(#1:#2-#3:#4)
    \dthtrunc\relax}

   \def\timediffnum{\dthtrunc}


Then

   \timediffprn(10:15-16:00)

prints 5.75 and

   \timediffprn(10:15-01:00)

prints 14.75. To use the time difference as a number for further  
computations, use the commands

   \timediffcalc

and

   \timediffnum

in tandem as in the attached file. (Not a very elegant solution and I  
will try to modify them later).

Regards

Krishnan






More information about the texhax mailing list