Results 1 to 2 of 2

Thread: Calculating time and a half

  1. #1
    Guest
    I'm trying to take the total time than is in lblOTHours * 1.5 I'm having no luck at all. Help me out.



    'Checks to see if there is overtime
    If EndTime > OTLimit Then

    'Calculates OT Hours
    NumHoursOT = DateDiff("h", OTLimit, EndTime)
    NumMinutesOT = DateDiff("n", OTLimit, EndTime)
    NumMinutesOT = NumMinutesOT - (60 * NumHoursOT)
    lblOTHours.Caption = NumHoursOT & ":" & NumMinutesOT

  2. #2
    Junior Member
    Join Date
    Mar 1999
    Posts
    27
    Try this little tidbit - I made everything variables - if they're not variables and they're textboxes then make sure to add the Val() statement...The IIf statement is to ensure proper formatting (try it without the IIf and you'll see what I mean) - anyways - this is what I came up with:

    Code:
        Dim OTLimit As Date, EndTime As Date, NumMinutesOT%
        Dim NumHours%, TotalTime As String
        'Dummy values for the OTLimit and EndTime
        OTLimit = "3:00"
        EndTime = "9:00"
        NumMinutesOT = DateDiff("n", OTLimit, EndTime)
        'This Debug.Print would be in your lblOTHours
        Debug.Print "OT Hours: " & Str$(NumMinutesOT \ 60) & ":" & IIf(NumMinutesOT Mod 60 < 10, "0" & Trim$(Str$(NumMinutesOT Mod 60)), Trim$(Str$(NumMinutesOT Mod 60)))
        NumMinutesOT = NumMinutesOT * 1.5
        NumHours = NumMinutesOT \ 60    'Notice that is Integer Divide
        NumMinutesOT = NumMinutesOT Mod 60
        TotalTime = NumHours & ":" & IIf(NumMinutesOT < 10, "0" & NumMinutesOT, NumMinutesOT)
        'This Debug.Print is your lblOTHours * 1.5
        Debug.Print "OT AT 1.5: " & TotalTime
    Hope this helps! Good Luck!

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