Time Math

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am looking for guidance on the best way to perform math on times that are in the format of military time i.e. 0700, 1600. Specifically, I am in need of advice on methods of subtracting depart time from arrive time and obtaining total hours. I have considered using the Left and Right functions to break apart the respective time values, then perform conversions to total minutes then substract depart from arrival, then convert total hours. If there is an easier way, let me know, much appreciated

Thank you in advance for your input.
 
How about converting the times into their decimal equivalent. Then you
subtract the 2 numbers which will give the results in hours. Then take the
decimal part of the answer and convert back to minutes.

TotalTime = (CDbl(left([StartTime],2)+(CDbl(right([StartTime],2)/60)) -
(CDbl(left([EndTime],2)+(CDbl(right([EndTime],2)/60))
TotalHours = Cint([TotalTime])
TotalMinutes = CInt(([TotalTime] - [TotalHours]) * 60)

Kelvin

mbox204 said:
I am looking for guidance on the best way to perform math on times that
are in the format of military time i.e. 0700, 1600. Specifically, I am in
need of advice on methods of subtracting depart time from arrive time and
obtaining total hours. I have considered using the Left and Right functions
to break apart the respective time values, then perform conversions to total
minutes then substract depart from arrival, then convert total hours. If
there is an easier way, let me know, much appreciated.
 
Why not insert a colon after the first two characters of the time and
convert them to datetime. You can then use the DateDiff function.
eg DateDiff("n",#07:00#",#16:00#) = 540. "n" is used for minutes in date
format to distinguish it from months. If you use "h" for hours you get
integral values

Rod Scoullar
 
Back
Top