hours worked

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lee123
    Contributor
    • Feb 2007
    • 556

    hours worked

    i have a form with timestarted and timeended and i have asked this question before but in access the way they did it was in a query but i don't know how to work the query in vb6 so maybe one of you people can help me i am trying to figure out how i can get the hoursworked on my form from the fields timestarted & timeended i thought you could do this:

    Code:
    Private Sub HoursWorked_Change()
    Dim Hoursworked as integer
    
    Hoursworked = (timeended) - (timestarted)
    
    End Sub
    but as as you have guessed it didn't work, so if anyone knows how to do this please help!!!!

    lee123
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Use the DateDiff() function.

    Comment

    • lee123
      Contributor
      • Feb 2007
      • 556

      #3
      Hey killer42, thanks for that. i have done this it works but if i have a wierd time in there like 12:15pm to 2:45pm it doesn't give me all the time it just gives me the hours the way i have done this is this:

      Code:
      Private Sub HoursWorked_GotFocus()
      
          HoursWorked = DateDiff("h", TimeEnded, TimeStarted)
          
      End Sub
      please tell me if i did this right or is there a way i can fix this? oh i also have an amount due field on this how would i calculate the hoursworked times a rate such as, if i worked 3 hr and the rate is $10.00 how would i get the amount due to say $30.00

      lee123

      Comment

      • jamesd0142
        Contributor
        • Sep 2007
        • 471

        #4
        Try something like this:


        [code=text]
        Dim HoursWorked As String
        Dim minutesworked
        Dim TimeStarted As Date = "02/3/2008 12:58:22 PM"
        Dim TimeEnded As Date = System.DateTime .Now

        minutesworked = DateDiff(DateIn terval.Minute, TimeStarted, TimeEnded)
        HoursWorked = CInt(minuteswor ked) / 60

        TextBox1.Text = HoursWorked
        [/code]

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          To expand slightly on James's example...

          [code=vb]
          Dim TotalMinutes As Long
          Dim HoursWorked As Long
          Dim MinutesWorked as Long

          TotalMinutes = DateDiff("n", TimeStarted, TimeEnded) ' Note, VB6 format
          HoursWorked = Int(TotalMinute s / 60)
          MinutesWorked = TotalMinutes - 60 * HoursWorked
          [/code]

          Comment

          Working...