+ Reply to Thread
Results 1 to 18 of 18

Need help calculating hours and minutes in a rolling 24 hour period with "If/Then" also

  1. #1
    Registered User
    Join Date
    06-08-2013
    Location
    Greenwood, DE
    MS-Off Ver
    Excel 2007
    Posts
    9

    Need help calculating hours and minutes in a rolling 24 hour period with "If/Then" also

    I'm creating a time sheet to calculate when a person has accumulated 16 hours within a 24 hour period. e.g.
    1st work assignment: 7 AM til 3:30 PM with a half hour break for lunch. = 8.5 hours
    2nd work assignment: 5:21 PM til 8:42 PM = 3 hours. so the total now is 11.5 BUT, because the interval between 3:30 and 5:21 is less than 2 hours (120 minutes), the time continues to accumulate, therefore, I need the total to be 13 hours.
    If the 2nd work assignment had started at 5:31 PM, then the interval time would not count, thus the total would be 11.5.
    Time Sheet.xlsx
    The next problem is, if the second work assignment is less than 2 hours, I need to accumulate 2.5 hours.
    I also don't know how to calculate the hours if the second work assignment starts at 23:42 on day one and stops at 3:08 on day 2.
    Thanks for your help.

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Need help calculating hours and minutes in a rolling 24 hour period with "If/Then" als

    First of all, you don't write
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    because there is a SUM function where you write
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Same for other.

    Second, I don't understand. You did get 13 hours as result?

  3. #3
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,936

    Re: Need help calculating hours and minutes in a rolling 24 hour period with "If/Then" als

    Hi and welcome to the forum

    1 thing to remember about working with time in excel, is that excel treats time as a fraction/decimal of 1. So 6am is actually 0.25, 12 noon is 0.5 etc. So if you are working with time that goes from 1 day to the next, you need to subtract the start time from 1.00 and then the end time (in simple terms)
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  4. #4
    Registered User
    Join Date
    06-08-2013
    Location
    Greenwood, DE
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Need help calculating hours and minutes in a rolling 24 hour period with "If/Then" als

    Thanks for the reply. When I changed the formula as you stated, I get 2:46 as a total. And yes, I did get 13, but, when I change B10 to 17:35, the formula doesn't work unless I edit reverse the "<" sign . . .
    Also, how do I calculate the time when I start the next work assignment at 23:32 and end it the next day at 3:08 in the morning?

  5. #5
    Registered User
    Join Date
    06-08-2013
    Location
    Greenwood, DE
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Need help calculating hours and minutes in a rolling 24 hour period with "If/Then" als

    Can you give me an example? Start at 23:42 on day one and end at 3:08 on day 2 . . . on my fingers its 3.5 hours, but I want Excel to tell me that.

  6. #6
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,936

    Re: Need help calculating hours and minutes in a rolling 24 hour period with "If/Then" als

    Assume you have A1=23:42 B1=3:08
    C1=(1-A1)+B1 .......... = 3:26 which is 3 hours 26 minutes or 3.433 hours

  7. #7
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,936

    Re: Need help calculating hours and minutes in a rolling 24 hour period with "If/Then" als

    To test for the today-tomorrow situation...
    =IF(A1>B1,(1-A1)+B1,B1-A1)

    So if you swap those times around, you would get 20:34 20 hours 34 minutes

  8. #8
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,728

    Re: Need help calculating hours and minutes in a rolling 24 hour period with "If/Then" als

    Assume 23:42 is in A1 and 3:08 in B1 - put this formula in C1:

    =B1-A1+(A1>B1)

    Format the cell as time, and you should see 3:26 - not sure why you think it should be 3.5, but if you want to see the result in hours, then you can do this:

    =(B1-A1+(A1>B1))*24

    and format the cell as General or Number - you should see 3.43333.

    Hope this helps.

    Pete

  9. #9
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,936

    Re: Need help calculating hours and minutes in a rolling 24 hour period with "If/Then" als

    Thanks Pete, I keep forgetting the (A1>B1) method lol

  10. #10
    Registered User
    Join Date
    06-08-2013
    Location
    Greenwood, DE
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Need help calculating hours and minutes in a rolling 24 hour period with "If/Then" als

    Thanks - I really appreciate the help.
    As to why I think its 3.5 hours from 23:42 to 3:08 - it's because (in our world) the computed time starts at 23:30 (at 23:45 the time would have started at 12 AM) and the end time of 3:08 backs up to 3:00., so the time was calculated as 11:30 PM to 3 AM - or 3.5 hours.
    (e.g. from 01:45 till 02:14, the time starts at 02:00, from 02:15 till 02:44, time starts at 02:30 and so on - )
    Which brings up my next question:
    How can I get Excel to see it that way - and display it that way?

  11. #11
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,728

    Re: Need help calculating hours and minutes in a rolling 24 hour period with "If/Then" als

    Like this if you want it in hours:

    =(FLOOR(B1,1/24/4)-FLOOR(A1,1/24/4)+(A1>B1))*24

    This rounds each time down to quarter of an hour (that's why I have left it as 1/24/4 - easier to understand).

    Hope this helps.

    Pete

  12. #12
    Registered User
    Join Date
    06-08-2013
    Location
    Greenwood, DE
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Need help calculating hours and minutes in a rolling 24 hour period with "If/Then" als

    That is unbelievably AWESOME! Dude, you must think in code . . . I'm totally dazzled . . .

  13. #13
    Registered User
    Join Date
    06-08-2013
    Location
    Greenwood, DE
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Need help calculating hours and minutes in a rolling 24 hour period with "If/Then" als

    In A1 I have "15:30" in B1 I have "17:14". In Cell C1 I want so see "0" if B1-A1 is greater than 2 hours. If it's less than 2 hours, I want the actual time, rounded up or down as described above.

  14. #14
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,728

    Re: Need help calculating hours and minutes in a rolling 24 hour period with "If/Then" als

    You can do that with this:

    =MIN((FLOOR(B1,1/24/4)-FLOOR(A1,1/24/4)+(A1>B1))*24,2)

    Changes in red.

    Hope this helps.

    Pete

  15. #15
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,728

    Re: Need help calculating hours and minutes in a rolling 24 hour period with "If/Then" als

    Sorry, you want zero if the difference is greater than 2 hours ??

    Strange ...

    but you can do that with this formula:

    =IF((FLOOR(B1,1/24/4)-FLOOR(A1,1/24/4)+(A1>B1))*24>2,0,(FLOOR(B1,1/24/4)-FLOOR(A1,1/24/4)+(A1>B1))*24)

    Hope this helps.

    Pete

  16. #16
    Registered User
    Join Date
    06-08-2013
    Location
    Greenwood, DE
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Need help calculating hours and minutes in a rolling 24 hour period with "If/Then" als

    Well, When I paste that in, I get "1.5" in C1. That's fine. But if I change B1 to "17:35", it shows me "2", even if I change it to "23:50" it shows me "2". I need it to show me "0" if the difference is greater than 2 hours.

    Thank you so much for your help (and patience).

    BTW - I was in Carnforth, England back in '86. I became addicted to fish and chips! Can't find ANYTHING in the US that even comes close . . . sigh

  17. #17
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,728

    Re: Need help calculating hours and minutes in a rolling 24 hour period with "If/Then" als

    See my later post. Originally I thought you wanted the difference not to exceed 2 hours (e.g. the maximum allowed overtime), but then I re-read your post.

    Hope this helps.

    Pete

  18. #18
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,936

    Re: Need help calculating hours and minutes in a rolling 24 hour period with "If/Then" als

    wow thats a heck of a mouth-full Pete, now can you say that backwards?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1