+ Reply to Thread
Results 1 to 11 of 11

Formula Needed - Hours between times crossing midnight

  1. #1
    Registered User
    Join Date
    08-16-2017
    Location
    Sheffield, England
    MS-Off Ver
    2013
    Posts
    6

    Formula Needed - Hours between times crossing midnight

    Hi,

    New to this forum and in need of some help!

    At my workplace, people whos working hours fall between 10pm and 6am attract a higher rate of pay. I'd like a formula to work out how many hours fall within this timeframe based on the people's shifts. I've seen similar requests on the forum but can't get the solutions to work for me, maybe because the dates and times are in the same cell.

    I've attached an example of how the data gets taken out of our Workforce Optimisation system. I need to know how many hours fall between. I@m using Excel 2013.

    Many thanks!

    Adam
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,064

    Re: Formula Needed - Hours between times crossing midnight

    This works if the finish time is the same or the next day but not more than 24 hrs later, but obviously you wouldnt have anyone working 24hrs a day.

    =MAX(0,MIN(D2,INT(D2)+TIMEVALUE("06:00"))-MAX(C2,INT(C2)+TIMEVALUE("22:00"))+1)

    and copy down the column
    Last edited by Special-K; 08-17-2017 at 05:49 AM.
    Regards
    Special-K

    Ensure you describe your problem clearly, I have little time available to solve these problems and do not appreciate numerous changes to them.

  3. #3
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Formula Needed - Hours between times crossing midnight

    Sorry....

    I messed up.
    Last edited by mehmetcik; 08-17-2017 at 08:26 AM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  4. #4
    Registered User
    Join Date
    08-16-2017
    Location
    Sheffield, England
    MS-Off Ver
    2013
    Posts
    6

    Re: Formula Needed - Hours between times crossing midnight

    Thanks for the responses.
    Special-K, I found your formula worked fine where the finish time is the next day. I've attached a bit more data, showing that sometimes people don't work at all between those times, and as such they would not have any premium hours, in which case your formula doesn't work and gave the result as 07:15. Could you please let me know how to make it show that in such instances the number of hours is zero?

    mehmetcik, I'm afraid I couldn't get your forumla to work as it produced the result of 2 in all instances.

    Thank you

    Adam
    Attached Files Attached Files

  5. #5
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,064

    Re: Formula Needed - Hours between times crossing midnight

    Am still looking at this...

  6. #6
    Registered User
    Join Date
    08-16-2017
    Location
    Sheffield, England
    MS-Off Ver
    2013
    Posts
    6

    Re: Formula Needed - Hours between times crossing midnight

    Just wondering if you managed to get chance to re-look at this?

    Many thanks

  7. #7
    Forum Expert
    Join Date
    10-10-2016
    Location
    Sheffield
    MS-Off Ver
    365 and rarely 2016
    Posts
    3,210

    Re: Formula Needed - Hours between times crossing midnight

    Assuming people's shifts don't go to a huge number of hours (in excess of 16) perhaps the following

    =IF(INT(D2)-INT(C2)>0,1-MAX(MOD(C2,1),22/24)+MIN(MOD(D2,1),6/24),IF(MOD(D2,1)>22/24,MOD(D2,1)-MAX(MOD(C2,1),22/24),0)+IF(MOD(C2,1)<6/24,MIN(MOD(D2,1),6/24)-MOD(C2,1),0))

  8. #8
    Forum Expert
    Join Date
    10-10-2016
    Location
    Sheffield
    MS-Off Ver
    365 and rarely 2016
    Posts
    3,210

    Re: Formula Needed - Hours between times crossing midnight

    Just seen your location. Its a small world!

  9. #9
    Forum Contributor Toonies's Avatar
    Join Date
    07-30-2009
    Location
    Newcastle, UK
    MS-Off Ver
    Excel 2016
    Posts
    503

    Re: Formula Needed - Hours between times crossing midnight

    try
    Please Login or Register  to view this content.
    Last edited by Toonies; 08-29-2017 at 01:05 PM. Reason: amended formula

  10. #10
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Formula Needed - Hours between times crossing midnight

    With time boundaries in E1:F1 this formula in E2 filled down returns whole decimal hours.
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Row\Col
    A
    B
    C
    D
    E
    F
    1
    Employee Number
    Employee
    Shift Start
    Shift End
    10:00:00 PM
    6:00:00 AM
    2
    10001
    Mark
    7/20/2017 20:30
    7/21/2017 7:45
    3
    10001
    Mark
    7/21/2017 20:30
    7/22/2017 7:45
    4
    10001
    Mark
    7/22/2017 20:30
    7/23/2017 7:45
    24
    5
    10002
    Sam
    7/16/2017 20:30
    7/17/2017 7:45
    6
    10002
    Sam
    7/17/2017 20:30
    7/18/2017 7:45
    7
    10002
    Sam
    7/18/2017 20:30
    7/19/2017 7:45
    8
    10002
    Sam
    7/19/2017 20:30
    7/20/2017 7:45
    32
    9
    10003
    Tom
    7/16/2017 20:30
    7/17/2017 7:45
    10
    10003
    Tom
    7/17/2017 20:30
    7/18/2017 7:45
    11
    10003
    Tom
    7/18/2017 20:30
    7/19/2017 7:45
    12
    10003
    Tom
    7/19/2017 20:30
    7/20/2017 7:45
    32
    13
    10004
    Oli
    7/20/2017 20:30
    7/21/2017 7:45
    14
    10004
    Oli
    7/21/2017 20:30
    7/22/2017 7:45
    15
    10004
    Oli
    7/22/2017 20:30
    7/23/2017 7:45
    24
    16
    10005
    Elle
    7/17/2017 16:00
    7/18/2017 0:00
    17
    10005
    Elle
    7/17/2017 16:00
    7/18/2017 0:00
    18
    10005
    Elle
    7/18/2017 16:00
    7/19/2017 0:00
    19
    10005
    Elle
    7/19/2017 16:00
    7/20/2017 0:00
    20
    10005
    Elle
    7/20/2017 16:00
    7/21/2017 0:00
    10
    Dave

  11. #11
    Registered User
    Join Date
    08-16-2017
    Location
    Sheffield, England
    MS-Off Ver
    2013
    Posts
    6

    Re: Formula Needed - Hours between times crossing midnight

    davsth - This works just how I need it! Thank you so much.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Tiimelog - Time Difference Crossing Over or Past Midnight
    By mycon73 in forum Excel General
    Replies: 6
    Last Post: 10-20-2016, 06:41 AM
  2. [SOLVED] Looking for MAX formula when times span or cross midnight
    By Rex411 in forum Excel General
    Replies: 6
    Last Post: 02-16-2016, 08:22 PM
  3. [SOLVED] formula to calculate time difference crossing midnight
    By ditorejax in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-06-2014, 08:27 PM
  4. Time crossing midnight
    By belle08 in forum Excel General
    Replies: 4
    Last Post: 01-27-2014, 03:47 PM
  5. Replies: 13
    Last Post: 11-04-2013, 02:30 AM
  6. Excel 2007 : Formula - hours worked past midnight
    By Belatrix101 in forum Excel General
    Replies: 10
    Last Post: 12-18-2009, 03:45 AM
  7. Hours spanning midnight on gnatt (formula inc)
    By r1ch1nxdcc in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-15-2009, 09:48 AM

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