Shift - Day and Night, working hours out

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

2. 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!

3. 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. 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. 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. Maybe:
``Please Login or Register  to view this content.``

7. 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
Originally Posted by Paul
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. 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.

9. 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?

Kring

10. 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.

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.

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

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