-
Hello
I am working on a Time Clock Program and I can find the difference between the clock in time and the clock out time. Is there a vb function to do this? or any thoughts?
My Dream Function would be
HoursWorked = SomeFunction(ClockIn,ClockOut)
If Life could be so good?
Thank you
William
-
It's named Datediff
DateDiff("h", date1, date2)
-
Hi William
Here's a silly one. It won't work if the month rolls-over though. Should be fairly simple to fix.
Make a form with a Command button called Command1, then
Code:
Dim T1 As Date
Function SomeFunction(ByVal InTime As Date, ByVal OutTime As Date) As String
'Returns the difference between InTime and OutTime (in minutes)
InTime = Day(InTime) * 1440 + Hour(InTime) * 60 + Minute(InTime)
OutTime = Day(OutTime) * 1440 + Hour(OutTime) * 60 + Minute(OutTime)
SomeFunction = OutTime - InTime
End Function
Private Sub Command1_Click()
ttl = SomeFunction(T1, Now)
m$ = "Hours: " & vbTab & ttl \ 60 & vbCrLf
m$ = m$ & "Minutes: " & vbTab & ttl Mod 60
MsgBox m$, vbInformation, "Time Taken"
End Sub
Private Sub Form_Load()
T1 = Now
End Sub
-
DateDiff
Well, that saves a lot of time. I didn't know about the DateDiff function. Thanks Kedaman
-
Cool, thanks Andrew
But What is The Mod keyword for?
and I didn't know about the DateDiff function either.
William
-
The Mod keyword is used to divide two numbers and only return the remainder.
-
FWIW, another variation on the theme
Code:
Function SomeOtherFunction(ClockIn As Date, ClockOut As Date) As Single
Dim Oops As Date
' Return difference between InTime and OutTime (in hours)
If ClockIn > ClockOut THEN
Oops = ClockIn
ClockIn = ClockOut
ClockOut = Oops
End If
SomeOtherFunction = 1440 * (ClockOut - ClockIn)
End Function
[Edited by Mongo on 07-01-2000 at 05:01 AM]