+ Reply to Thread
Results 1 to 10 of 10

Shift - Day and Night, working hours out

  1. #1
    Registered User
    Join Date
    10-23-2008
    Location
    UK
    Posts
    1

    Shift - Day and Night, working hours out

    Hi,

    I am trying to do a table to count the hours i have worked, including how many are at night and day.

    for example

    22:00 - 06:00 is our night hours
    06:00 - 22:00 is our day hours.

    if i clocked on at 05:00 and clocked off at 10:00 i would of worked

    1 hour at night
    4 hours at day

    can someone work a formula to help me with this please. i would like to enter my start time in one cell, finish time in another cell. then the values to populate "day hours" and "night hours"

    Thanks
    Last edited by fwddesign; 10-23-2008 at 05:26 PM.

  2. #2
    Forum Moderator Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,799
    Hi FWD,

    Well, they're not the prettiest formulas, but I think they cover any possible scenarios for your start and end times. This assumes your Start Time is in A2 and your End Time is in B2 (adjust any references of A2 and B2 to your actual cells, of course).

    To calculate Day Hours:
    =IF(OR(AND(A2<=TIME(6,0,0),B2>=TIME(6,0,0),B2<=TIME(22,0,0)),AND(A2>=TIME(22,0,0),B2>=TIME(6,0,0),B2<=TIME(22,0,0))),24*(B2-TIME(6,0,0)),IF(AND(AND(A2>=TIME(6,0,0),A2<=TIME(22,0,0)),AND(B2>=TIME(6,0,0),B2<=TIME(22,0,0))),24*(B2-A2),IF(AND(A2>=TIME(6,0,0),A2<=TIME(22,0,0),OR(B2<=TIME(6,0,0),B2>=TIME(22,0,0))),24*(TIME(22,0,0)-A2),IF(AND(A2<=TIME(6,0,0),B2>=TIME(22,0,0)),16,0))))

    To calculate Night Hours:
    =IF(AND(A2<=TIME(6,0,0),B2<=TIME(6,0,0)),(B2-A2)*24,IF(AND(A2<=TIME(6,0,0),B2>=TIME(6,0,0),B2<=TIME(22,0,0)),(TIME(6,0,0)-A2)*24,IF(AND(A2<=TIME(6,0,0),B2>=TIME(22,0,0)),(24*(B2-TIME(22,0,0))+24*(TIME(6,0,0)-A2)),IF(AND(A2>=TIME(6,0,0),A2<=TIME(22,0,0),B2>=TIME(22,0,0)),(B2-TIME(22,0,0))*24,IF(AND(A2>=TIME(6,0,0),A2<=TIME(22,0,0),B2<=TIME(6,0,0)),(B2-TIME(0,0,0))*24+2,IF(AND(A2>=TIME(22,0,0),B2<=TIME(6,0,0)),(24-((A2-B2))*24),IF(AND(A2>=TIME(22,0,0),B2>=TIME(6,0,0)),2-((A2-TIME(22,0,0))*24)+6,0)))))))

    Maybe someone else has a better idea, but these seem to work. Hope that helps!
    Last edited by Paul; 10-23-2008 at 09:13 PM. Reason: Updated DAY HOURS formula, missed part of the 2nd AND in the 1st OR function.

  3. #3
    Forum Expert darkyam's Avatar
    Join Date
    03-05-2008
    Location
    Houston, TX
    MS-Off Ver
    2013
    Posts
    2,191
    I did some brief testing of these and they work so far. For day:
    Please Login or Register  to view this content.
    and for night:
    Please Login or Register  to view this content.
    assuming B1 is where you had the formula for day hours. A1 is start time in these and A2 is end time.

  4. #4
    Forum Moderator Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,799
    Yam.. that is insanely easier than what I came up with, lol.

    One thing I've found when testing is if the Start time and End time are both between midnight (12:00 AM) and 6:00 AM, the Day formula errors, and the Night formula always registers (6:00AM - StartTime) hours.

    Oh, and if you put the same Start and End time, both formulas calculate incorrectly. Of course, why would you have the same start and end times, but I'm just sayin'!

    Good work!

  5. #5
    Forum Expert darkyam's Avatar
    Join Date
    03-05-2008
    Location
    Houston, TX
    MS-Off Ver
    2013
    Posts
    2,191
    Thought it'd be a quick fix, but each new attempt seems to introduce a new error. Easier is only better than more complex if it also works.
    On the bright side, at least the second formula should work provided the start and end times aren't equal. I figured there'd never be a 24-hour shift.

  6. #6
    Forum Expert darkyam's Avatar
    Join Date
    03-05-2008
    Location
    Houston, TX
    MS-Off Ver
    2013
    Posts
    2,191
    Maybe:
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    06-12-2012
    Location
    Egypt
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Shift - Day and Night, working hours out

    Daer Paul,Thanks for your efforts concerning this subject, But may I ask for a favor, I Tried to re modify these formulas according to our company rules but It didn't work with me, May I Ask you how to this re modification

    I'll be apperciated

    Thanks
    Wael
    Quote Originally Posted by Paul View Post
    Hi FWD,

    Well, they're not the prettiest formulas, but I think they cover any possible scenarios for your start and end times. This assumes your Start Time is in A2 and your End Time is in B2 (adjust any references of A2 and B2 to your actual cells, of course).

    To calculate Day Hours:
    =IF(OR(AND(A2<=TIME(6,0,0),B2>=TIME(6,0,0),B2<=TIME(22,0,0)),AND(A2>=TIME(22,0,0),B2>=TIME(6,0,0),B2<=TIME(22,0,0))),24*(B2-TIME(6,0,0)),IF(AND(AND(A2>=TIME(6,0,0),A2<=TIME(22,0,0)),AND(B2>=TIME(6,0,0),B2<=TIME(22,0,0))),24*(B2-A2),IF(AND(A2>=TIME(6,0,0),A2<=TIME(22,0,0),OR(B2<=TIME(6,0,0),B2>=TIME(22,0,0))),24*(TIME(22,0,0)-A2),IF(AND(A2<=TIME(6,0,0),B2>=TIME(22,0,0)),16,0))))

    To calculate Night Hours:
    =IF(AND(A2<=TIME(6,0,0),B2<=TIME(6,0,0)),(B2-A2)*24,IF(AND(A2<=TIME(6,0,0),B2>=TIME(6,0,0),B2<=TIME(22,0,0)),(TIME(6,0,0)-A2)*24,IF(AND(A2<=TIME(6,0,0),B2>=TIME(22,0,0)),(24*(B2-TIME(22,0,0))+24*(TIME(6,0,0)-A2)),IF(AND(A2>=TIME(6,0,0),A2<=TIME(22,0,0),B2>=TIME(22,0,0)),(B2-TIME(22,0,0))*24,IF(AND(A2>=TIME(6,0,0),A2<=TIME(22,0,0),B2<=TIME(6,0,0)),(B2-TIME(0,0,0))*24+2,IF(AND(A2>=TIME(22,0,0),B2<=TIME(6,0,0)),(24-((A2-B2))*24),IF(AND(A2>=TIME(22,0,0),B2>=TIME(6,0,0)),2-((A2-TIME(22,0,0))*24)+6,0)))))))

    Maybe someone else has a better idea, but these seem to work. Hope that helps!

  8. #8
    Registered User
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,149

    Re: Shift - Day and Night, working hours out

    Wsalahz,

    Welcome to the Forum, unfortunately:

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  9. #9
    Registered User
    Join Date
    07-28-2015
    Location
    Philippines
    MS-Off Ver
    2007
    Posts
    6

    Re: Shift - Day and Night, working hours out

    Hi Paul!
    This helped me a lot!!

    I will be asking for your help in a more specific condition. So our night shift starts at 10PM and ends at 6am the next day. However, during holidays, we take note of the regular hours and night diff of the regular day and holiday regular hours and night diff. Simply put, can you help me separate the reg hrs and night diff of day 1 from reg hrs and night diff of day 2?

    Appreciate your help.

    Kring

  10. #10
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Excel 2016
    Posts
    10,064

    Re: Shift - Day and Night, working hours out

    Hi King & Welcome to the Forum,

    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.
    HTH
    Regards, Jeff

+ 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