Working w/Times in a Form | Subtracting

J

JK

I have a form (AC03) with a Start Time field (combo box) and an End Time
field (combo box); I then have a TotalDowntime field which subtracts the
EndTime from the StartTime to come up with the total hrs & mins the machine
being worked on was down.

TotalDowntime: Format([EndTime]-[StartTime],"hh:nn")

However, if a machine goes down at say 11:00 PM and is not restored until
1:00 AM the TotalDowntime value is 22:00 (22hrs) when it should be 02:00
(2hrs.)

Any idea how to correct this problem?

Thx so much!

Jason
 
M

Marshall Barton

JK said:
I have a form (AC03) with a Start Time field (combo box) and an End Time
field (combo box); I then have a TotalDowntime field which subtracts the
EndTime from the StartTime to come up with the total hrs & mins the machine
being worked on was down.

TotalDowntime: Format([EndTime]-[StartTime],"hh:nn")

However, if a machine goes down at say 11:00 PM and is not restored until
1:00 AM the TotalDowntime value is 22:00 (22hrs) when it should be 02:00
(2hrs.)

Any idea how to correct this problem?


The two time values need their date parts too.

You also need to use DateDiff function instead of just
subtracting the two times.

If the time difference can possibly be more than 24 hours
then, it's another reason to use DateDiff.

Using DateDiff("n", ...) to get the number of minutes will
then provide a number that needs to be used in an expression
to display it in hours and minutes:

TotalDowntime \ 60 & Format(TotalDowntime Mod 60, "\:00")
 

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