Consulting

Results 1 to 8 of 8

Thread: Solved: Time calculation

  1. #1
    VBAX Tutor
    Joined
    Jan 2006
    Posts
    248
    Location

    Solved: Time calculation

    I have a starting time in cell D8 which is 03:09 and finishing time in D9 which is 12:20 for a total of 9:11 hours.

    I am trying to do a calculation in cell D10 that would say if the hours are equal to 8 or less then = to D9, if D9 is greater than 8 then I want 9:11 hours minus 8 hours then times the difference by 1.5 then add this to 8 hours.

    This should then give a figure of 9:46 hours.

    Hope this makes some sense.

  2. #2
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Barry

    Try this formula.

    =IF(D9-D8>TIME(8,0,0), TIME(8,0,0)+((D9-D8)-TIME(8,0,0))*1.5, D9-D8)

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Another way

    =MAX((D9-D8)-8/24,0)*1.5+MIN(8/24,D9-D8)

  4. #4
    Here's a function for you to try:
    [vba]Function TimeDiff(ETim As Date, LTim As Date)
    Application.Volatile (False)
    If LTim - ETim > 0 _
    Then TimeDiff = Format(LTim - ETim, "h:mm") _
    Else TimeDiff = Format(1 + LTim - ETim, "h:mm")
    End Function [/vba]
    where ETim is the "early" time and LTim is the "late" time.

  5. #5
    VBAX Tutor
    Joined
    Jan 2006
    Posts
    248
    Location
    Thanks guys, I will give them a try tomorrow and see how I go.

  6. #6
    VBAX Tutor
    Joined
    Jan 2006
    Posts
    248
    Location
    Am still getting ######## when starting time is before midnight and finish time is after midnight.

    Have included a file to show this cells are formated as custom hh:mm.

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    =MAX((MOD(D9-D8,1))-8/24,0)*1.5+MIN(8/24,MOD(D9-D8,1))

  8. #8
    VBAX Tutor
    Joined
    Jan 2006
    Posts
    248
    Location
    Thanks XLD and the other guys problem solved.

Posting Permissions

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