Results 1 to 7 of 7

Thread: Math with Time var's

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 1999
    Location
    Reno, NV
    Posts
    57
    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


  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    It's named Datediff
    DateDiff("h", date1, date2)
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Lively Member
    Join Date
    Jun 2000
    Posts
    82
    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
    Andrew Empson
    vb6(ent) SP4

  4. #4
    Lively Member
    Join Date
    Jun 2000
    Posts
    82

    Smile DateDiff

    Well, that saves a lot of time. I didn't know about the DateDiff function. Thanks Kedaman
    Andrew Empson
    vb6(ent) SP4

  5. #5

    Thread Starter
    Member
    Join Date
    Apr 1999
    Location
    Reno, NV
    Posts
    57
    Cool, thanks Andrew
    But What is The Mod keyword for?
    and I didn't know about the DateDiff function either.

    William

  6. #6
    Guest
    The Mod keyword is used to divide two numbers and only return the remainder.

  7. #7
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Leavenworth KS USA
    Posts
    482
    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]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width