calculate period between 2 Times

bee55

Registered User.
Local time
Today, 12:43
Joined
Oct 27, 2011
Messages
50
Hi every body
i create form to calculate the difference between clock-in time and clock-out time, what is the code to do that
i have 2 fields the field 1 name clockin
field 2 name clockout

i have a text box to display result equal the period between time1 and time 2
thanks
 
me.Resultbox = me.Clockout - me.clockin

That what you are looking for?
 
me.Resultbox = me.Clockout - me.clockin

That what you are looking for?

the data type of (clockin and clockout fields) are time not number
 
Date (and time) are for all intents and purposes the same as a number field only with a "format" on it to display date/time.
 
Date (and time) are for all intents and purposes the same as a number field only with a "format" on it to display date/time.

thank you
i find the reply

Code:
Private Sub Clock_Out_AfterUpdate()
Dim X, Y, Z As Long
X = DateDiff("n", Clock_In, Clock_Out)
X = X / 60
Z = Int(X)
Y = (X - Z) * 60
Period = Z & ":" & Y
End Sub

i calculate the minuts first and then i convert it to number
 
1)
Dim X, Y, Z As Long
isnt "right" that should be
Dim X As Long, Y As Long, Z As Long

2)
why that difficult stuff when you can "simply" do
Period = Format(Clock_out-clock_id, "HH:MM")
 
1)
Dim X, Y, Z As Long
isnt "right" that should be
Dim X As Long, Y As Long, Z As Long

2)
why that difficult stuff when you can "simply" do
Period = Format(Clock_out-clock_id, "HH:MM")

that is fine
great thanks
 
since X, Y and Z are all long and assume X=100

X = X / 60 =100/60=2
Z = Int(X)=2
Y = (X - Z) * 60=(2-2)*60=0

is this what you want?

Suggest X wants to be double, not long

X = X / 60 =100/60=1.66666666
Z = Int(X)=1
Y = (X - Z) * 60=(1.6666-1)*60=40
 

Users who are viewing this thread

Back
Top Bottom