Computing total hours

calimlimrodel

Registered User.
Local time
Tomorrow, 06:46
Joined
Feb 12, 2008
Messages
10
Hi there,

Good day to all!!

Need your help guys, I have a form called Ovetime Monitoring Form and there a text field named [Timefrm] and [TimeTo] when I put some on that field example 22:00 for the [Timefrm] and 06:00 for [TimeTo], the field for [TotalOTHrs] is -16 instead of 8hrs.
Please see attached for more detail.....

many thanks!
 

Attachments

Hi,

make sure that your fields are set to date datatype and not number.

Also search this forum for calculate time, as there are several threads how to calculate it.
 
How do you know that the 22:00 time is the day before the 6:00 time? Because it is logical that it would be and that elapsed times can't be negative so your brain interprets the data that way. However that logic is not explicit in your data. 6-22= -16 is a correct answer if no other data is supplied.

If your data was (14-Mar-2008 06:00)-(13-Mar-2008 22:00) then you would get 8 as the answer.
 
This code allows for the TimeTo occurring after midnight.
Code:
If TimeTo <= TimeFrm Then
  Me.TotalOTHrs  = (DateDiff("n", TimeFrm, TimeTo) + 1440)/60
Else
  Me.TotalOTHrs  = DateDiff("n", TimeFrm, TimeTo)/60
End If
 

Users who are viewing this thread

Back
Top Bottom