Help with Time Calculation

  • Thread starter Thread starter jessicaskinner81
  • Start date Start date
J

jessicaskinner81

I need help calculating the difference between a Time In field and
Time Out field. I have the code working in Excel, but I am not suire
how to encorporate this into a form in Access.

Excel expression - =IF((OR(D6="",D5="")),0,IF((D6<D5),((D6-D5)*24)+24,
(D6-D5)*24))

Please help!
 
Hi (e-mail address removed),
let's say D5 is timein and D6 is timeout. So that your excel expression
become in access
if isnull(timein) or isnull(timeout) then
expression=0
elseif timeout<timein then
expression=((timeout-timein)*24)+24
else
expression=(timeout-timein)*24
endif

HTH Paolo
 
Of course, if you want that in a single line, you can use IIf:

=IIf(IsNull(timein) OR
IsNull(timeout),0,IIf(timeout<timein,((timeout-timein)*24)+24,(timeout-timein)*24))
 
Jessica,
Dates and times are just a number, subject to simple math. How you display
them makes all the difference. The days are to the left of the decimal
(integer) and the time is to the right. So subtract the difference and format
accordingly.

You can put this in the form.oncurrent event
Me.ElapsedTime = Format(Me.StartDate - 1 - Me.StopDate, "Short Time")

or in the control source of the text box,

=[StartDate]-1-[StopDate]
and set the format to "Short Time"

I got this from Terry Kreft at a site with lots of helpful suggestions, try
it.
http://www.mvps.org/access/
 
Back
Top