How do I calculate time?

K

Kris

I know about the Diff Date function, it calculates the difference between dates. What will I use to calculate the difference between times? For example, a person was dispatched to a location for a delivery at 12:00PM and he departed at 2:00PM the total time is 2 hours. How do I do that ?
 
F

fredg

I know about the Diff Date function, it calculates the difference between dates. What will I use to calculate the difference between times? For example, a person was dispatched to a location for a delivery at 12:00PM and he departed at 2:00PM the total time is 2 hours. How do I do that ?

From the VBA Help files:
DateDiff("h",[Time1],[Time2])
 
P

Peter R. Fletcher

Provided that your times don't cross midnight:

dtElapsed = dtEnd - dtStart

If you use this approach, the result is expressed as a fraction of a
_day_, so you have to multiply it by 24 to get decimal hours or by
1440 to get decimal minutes.

If your clock times may cross midnight but the elapsed time is never
more than 24 hours, you can use:

dtElapsed = dtEnd - dtStart + IIF(dtEnd>dtStart,0,1)

If the elapsed time may be more than 24 hours, you have to keep track
of start and finish dates and times.

You can also use DateDiff, of course, with the appropriate qualifiers,
but I have never thought it worth the trouble for most time
calculations, since the simple approaches above work well in 99.8% of
applications

I know about the Diff Date function, it calculates the difference between dates. What will I use to calculate the difference between times? For example, a person was dispatched to a location for a delivery at 12:00PM and he departed at 2:00PM the total time is 2 hours. How do I do that ?

Please respond to the Newsgroup, so that others may benefit from the exchange.
Peter R. Fletcher
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top