+ Reply to Thread
Results 1 to 12 of 12

Calculating Day Night hours distribution

  1. #1
    Registered User
    Join Date
    12-08-2021
    Location
    Bulgaria
    MS-Off Ver
    MS Office 2016
    Posts
    6

    Calculating Day Night hours distribution

    Greetings fellow Excel lovers,

    I'm facing a bit of a conundrum - trying to split shift durations between Day and Night hours, where the night hours are between 22:00 and 06:00 and the output should be in numerical form. The hours I need to be split in two columns - Day hours (all hours in the range of > 06:00 and <= 22:00) and Night hours (> 22:00, <=6:00).

    Attached are some simulations of what hours can be seen and what is the desired outcome.

    So far I've created a If formula with 7 different conditions, but I'm confident there is a smarter way to do it, I just feel stuck with this.

    PS: I searched in the other topics, but couldn't find exactly what I needed, so I'm hoping somebody can help.
    Attached Files Attached Files
    Last edited by Dyakov; 07-04-2022 at 10:33 AM.

  2. #2
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Calculating Day Night hours distribution

    I made the following formulas:

    Please Login or Register  to view this content.
    Column G = Day Hours
    Column H = Night Hours

    See attached.

    WBD
    Attached Files Attached Files
    Office 365 on Windows 11, looking for rep!

  3. #3
    Registered User
    Join Date
    12-08-2021
    Location
    Bulgaria
    MS-Off Ver
    MS Office 2016
    Posts
    6

    Re: Calculating Day Night hours distribution

    Hey WideBoyDixon,

    Thank you for the helping hand

    Is there, however, a way of adding all day hours in only one column without adding extra ones? The file this formula will be used in has about 800 000 rows of data, so I'm trying to keep it as clean as possible. I really don't need a split of Day 1 or Day 2, rather all Day hours in one column, all Night hours in a separate column.

  4. #4
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Calculating Day Night hours distribution

    I figured you could hide the columns you didn't need to see. However, here's a solution with just three calculated columns.

    WBD
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    12-08-2021
    Location
    Bulgaria
    MS-Off Ver
    MS Office 2016
    Posts
    6

    Re: Calculating Day Night hours distribution

    This worked perfectly! Thanks a million WBD!

    You've saved me a bunch of time trying to configure my file.

    If it's not too much trouble, could you elaborate on how you've used the MAX(MIN functions with the night hour range, because reading the formulas, I wasn't able to fully grasp what you've done.

    And here is a virtual beer for the help

    Attachment 786170

  6. #6
    Forum Expert WideBoyDixon's Avatar
    Join Date
    10-03-2016
    Location
    Sheffield, UK
    MS-Off Ver
    365
    Posts
    2,182

    Re: Calculating Day Night hours distribution

    It's based on the formula here for days overlap:

    https://exceljet.net/formula/calcula...verlap-in-days

    But I often use it for time overlaps.

    WBD

  7. #7
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,466

    Re: Calculating Day Night hours distribution

    Dear Dyakov,

    I've simplified the formula, but they are still working correct:
    Duration (E2) = 24*(B2-A2+(A2>B2))
    Day Hours (F2) =24*MIN(E2/24;B2-J$2+(J$2>B2);I$2-J$2)
    Night Hours (G2) = E2-F2

    See attachment

    Hans Douwe
    Attached Files Attached Files
    Last edited by HansDouwe; 07-06-2022 at 05:26 AM.

  8. #8
    Forum Expert
    Join Date
    01-05-2013
    Location
    Singapore
    MS-Off Ver
    H&B2019
    Posts
    4,542

    Re: Calculating Day Night hours distribution

    Quote Originally Posted by WideBoyDixon View Post
    I figured you could hide the columns you didn't need to see. However, here's a solution with just three calculated columns.

    WBD
    WBD, thanks for the great formula! How would you adapt the formula if NH Start time is 12 midnight?

    Thank you.

  9. #9
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,466

    Re: Calculating Day Night hours distribution

    Dear WBD and Dyakov,

    If NH start 12 midnight (or later) you had to change:

    I$2-J$2 ---> I$2-J$2+(J$2>I$2)

    In this case of I2 = midnight J2>I2 = TRUE:
    I$2-J$2+(J$2>I$2) ==> 00:00 - 06:00 + 1 = 18:00

    Day Hours (F2) =24*MIN(E2/24;B2-J$2+(J$2>B2);I$2-J$2+(J$2>I$2)

    Hans Douwe
    Last edited by HansDouwe; 07-06-2022 at 06:27 AM.

  10. #10
    Registered User
    Join Date
    12-08-2021
    Location
    Bulgaria
    MS-Off Ver
    MS Office 2016
    Posts
    6

    Re: Calculating Day Night hours distribution

    Thanks a lot everyone!

    For some reason I wasn't able to find anything remotely similar to what I needed anywhere. Could be that I didn't know how to properly search for it, but still - it seems there is a lack of content for this specific case.

  11. #11
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,466

    Re: Calculating Day Night hours distribution

    What content are you still missing for this specific case Dyakov?

  12. #12
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,466

    Re: Calculating Day Night hours distribution

    My formula is not correct in all situatiions.
    I'll rectify my formula shortly.

+ 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. Night hours calculating
    By perobaja in forum Excel General
    Replies: 4
    Last Post: 03-27-2022, 04:36 PM
  2. [SOLVED] HOURS whats the difference of DAY hours & NIGHT hours per SHIFT formula
    By StephanRS in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-06-2021, 02:35 PM
  3. Replies: 3
    Last Post: 06-18-2014, 07:26 AM
  4. Calculating Day Rate and Night Rate Hours on a Timesheet
    By Hahnium in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 02-21-2013, 08:18 AM
  5. Replies: 4
    Last Post: 09-21-2012, 12:58 AM
  6. Replies: 2
    Last Post: 07-27-2012, 04:54 AM
  7. finding night hours (0-day,1-night) between ranges of data
    By sensation in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-09-2012, 09:08 AM

Tags for this Thread

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