+ Reply to Thread
Results 1 to 5 of 5

counting specific hours between two times

  1. #1
    Registered User
    Join Date
    10-26-2006
    Posts
    18

    counting specific hours between two times

    Please can someone help improve on this forumla. At the moment it works for all times except midnight. I am also sure that there must be a more efficient way of writing it. Basicly we pay single rate between 8.00am and 8.00pm at all other times and on bank holidays and weekdays we pay an enhanced rate. If I can calculate the standard hours then the remainder of the hours are enhanced.

    Aim to count how many work hours fall between a standard start time (SHS) and a standard end time (SHE) (currently 8.00am and 8.00pm), that do not fall on a weekend and are not a bank holiday.

    Column B = Start time (eg 06:00)
    Column C - End time (eg 22:00)

    Column D= date (from which day of week is derived)
    Column E = Y or N for whether it is a bank holiday or not.

    Current forumla in column P is
    =(IF(ISNONTEXT(D11),(IF(OR(WEEKDAY(D11)=1,WEEKDAY(D11)=7,E11="y"),0,IF(B11<shs,IF(C11<=shs,0,MIN(she,C11)-shs),0)+IF(AND(B11>=shs,B11<she),(O11/24)-IF(AND(C11>B11,C11>she),C11-she,0)-IF(C11<B11,MIN(C11,shs)+4/24,0),0)+IF(B11>=she,IF(AND(C11<B11,C11>=shs),MIN(C11,she)-shs,0),0))+A11),0)*24)-R11

    Some of our shifts start of end at midnight so I do need the formula to work for that time as well as other times.


    Thanks
    E

    nb for a start time of 6.00am and an end time of 22.00 the formula should calc standard hours of 12

    for a start time of 3.00am and end time of 10am the formula should count 2

    for a start time of 15:00 and and end time of 24:00 the forumla should count 5.
    Last edited by each; 04-20-2009 at 04:16 PM.

  2. #2
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: counting specific hours between two times

    Hello E,

    I assume, then that none of the shifts cross midnight, e.g. 21:00 - 08:00?

    If that's the case then this formula will get the hours between shs and she

    =IF(OR(WEEKDAY(D11,2)>5,E11="y"),0,(MIN(C11,she)-MAX(B11,shs))*24)

    For midnight as a start time input as 00:00 or as an end time 24:00

  3. #3
    Registered User
    Join Date
    10-26-2006
    Posts
    18

    Re: counting specific hours between two times

    Dear DaddyLL

    Thank you so much for your help.

    No shifts do not go on after midnight (or on the odd occasion that they might they can record that time on the next day).

    I still have a problem if the shift starts after 20:00 - the formula is returning a negative number.

    The same applies if some one is called out in the early hours to do say a 3:00am to 5:00am call out.


    thank you soooooo much.

    E

  4. #4
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: counting specific hours between two times

    Ah, sorry, I missed out a crucial MAX, try this version

    =IF(OR(WEEKDAY(D11,2)>5,E11="y"),0,MAX(MIN(C11,she)-MAX(B11,shs),0)*24)

  5. #5
    Registered User
    Join Date
    10-26-2006
    Posts
    18

    Re: counting specific hours between two times

    Thanks for your help Mr LL.
    I think I have it working now.

    E

+ 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