time sheet form with datediff function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • buddyr
    New Member
    • Apr 2007
    • 105

    time sheet form with datediff function

    Hello,
    I am now working on timesheet form users can input in time and out time.
    I wanted to have a txtbox called hours for each day that would calculate the hours.
    I have tried the datediff("h", me.txtboxIN, me.txtboxOUT) and "n"
    I am able to get the hours or the minutes - but cannot show them both together.

    I thought with the minutes there might be a way to divide and show hours and minutes.
    If a person came in at 7:30 am and left at 11:00 am -textboxHOURS should reflect 3.50 hours.
    any ideas
    thank you
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    Find the minutes then divide by 60:
    Code:
    datediff("n", me.txtboxIN, me.txtboxOUT)/60
    To round to 2 decimals (I think)
    Code:
    Round(datediff("n", me.txtboxIN, me.txtboxOUT)/60,2)
    Linq ;0)>

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      It's too close to bedtime, and I'm probably making this more complicated than need be, but assuming a Text Box on your Form is named txtHours, the following code placed in the AfterUpdate() Event of txtBoxOUT will produce the difference in HOURS:MINUTES Format, namely:
      Code:
      IN             OUT                txtHours
      7:15          11:00                 3:45
      Code:
      Private Sub txtBoxOUT_AfterUpdate()
      Dim intDiffInMin As Integer
      Dim txtIN As TextBox
      Dim txtOUT As TextBox
      Dim intHrs As Integer
      Dim intMins As Integer
      
      Set txtIN = Me![txtBoxIN]
      Set txtOUT = Me![txtBoxOUT]
      
        If Not IsNull(txtIN) And Not IsNull(txtOUT) Then
          If IsDate(txtIN) And IsDate(txtOUT) Then
            intDiffInMin = DateDiff("n", txtIN, txtOUT)
            intHrs = Int((intDiffInMin / 60))
            intMins = intDiffInMin - (intHrs * 60)
              Me![txtHours] = CStr(intHrs) & ":" & Format$(intMins, "00")
          End If
        End If
      End Sub

      Comment

      • buddyr
        New Member
        • Apr 2007
        • 105

        #4
        thank you
        missinglinq
        I wasn't able to get yours working- but I think I've been trying too hard on this and may be I inputed syntax wrong
        Adezi- I used your solution-IT WORKS
        thank you both

        Comment

        • shonyv
          New Member
          • Jun 2009
          • 2

          #5
          Try This

          =DateDiff("n",f ield,field)\60 & ":" & Format(DateDiff ("n",field,fiel d) Mod 60,"00")

          Shony

          Comment

          Working...