+ Reply to Thread
Results 1 to 11 of 11

Problem counting times that occur between a fixed range that includes midnight

  1. #1
    Registered User
    Join Date
    08-25-2016
    Location
    London, England
    MS-Off Ver
    MS 2011
    Posts
    8

    Unhappy Problem counting times that occur between a fixed range that includes midnight

    I want to count how many parties partially overlap a fixed range that includes midnight. I know the start/stop times of the parties.

    So for example, if a party starts at 7pm and goes until 1 am, it would fit my fixed range of 5pm-5am and be tallied.


    I would ideally like to create a function that checks both times as conditions, and counts it once if at least one overlaps the range I'm interested in. Is this possible? I can also imagine a scenario where I look at the first list of start times, filter, and then check the second list of end times.

    All the solutions I see floating around are for one time in between ranges, and rarely account for midnight.

  2. #2
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Problem counting times that occur between a fixed range that includes midnight

    Perhaps you could try using the mod function?

    A formula like this “=MOD(stop_time-start_time,1) will always give the right time difference even if it passes midnight.

    Alf

  3. #3
    Registered User
    Join Date
    08-18-2016
    Location
    Earth
    MS-Off Ver
    2010 and 2013
    Posts
    64

    Re: Problem counting times that occur between a fixed range that includes midnight

    You can do this... Where column A has your start times and Column B has your end times. In any free column put the following formula and copy down.

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    08-18-2016
    Location
    Earth
    MS-Off Ver
    2010 and 2013
    Posts
    64

    Re: Problem counting times that occur between a fixed range that includes midnight

    If you would like to return a true or false value instead of a 0 or 1 you can remove the last "+0"

  5. #5
    Registered User
    Join Date
    08-25-2016
    Location
    London, England
    MS-Off Ver
    MS 2011
    Posts
    8

    Re: Problem counting times that occur between a fixed range that includes midnight

    I tested your formula on my first set of times, but it returned 'true' when the answer is false for the conditions I'm looking to test. I did fudge the times a bit on my post so I could hash it out on my own. The real range I'm looking at is 8 pm - 8 am.
    a66fdbf6b6.png

  6. #6
    Registered User
    Join Date
    08-18-2016
    Location
    Earth
    MS-Off Ver
    2010 and 2013
    Posts
    64

    Re: Problem counting times that occur between a fixed range that includes midnight

    I just put in your data set and tested it and it works fine for me. On your cells check to make sure the dates for both the start time and end time are the same. Even though it only shows the times excel might be storing it as a date and time. Change the cell format to date and time to check. If you like you can upload the workbook and I can work it out on yours.

    Capture001.PNG

    IF there are dates associated to the cell. You should be able to use this formula and it will work.

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Last edited by Green Crocodile; 08-26-2016 at 01:39 AM.

  7. #7
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,908

    Re: Problem counting times that occur between a fixed range that includes midnight

    Try this ...

    =OR(A1>20/24,A1<8/24,B1>20/24,B1<8/24)

  8. #8
    Registered User
    Join Date
    08-25-2016
    Location
    London, England
    MS-Off Ver
    MS 2011
    Posts
    8

    Re: Problem counting times that occur between a fixed range that includes midnight

    Oh man, this is data I previously narrowed down to events that occurred on the same day! It was originally input as a date as well as a time, but I formatted the cell to show time so I wouldn't confuse myself.

  9. #9
    Registered User
    Join Date
    08-18-2016
    Location
    Earth
    MS-Off Ver
    2010 and 2013
    Posts
    64

    Re: Problem counting times that occur between a fixed range that includes midnight

    In that case this will work.

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Phuocam has a awesome way of doing it too. One thing I would add to his formula (not even sure you will come across the scenario) is this...

    =IF(B2 < A2,B2 < 20/24,OR(A2 > 20/24,A2 < 8/24,B2 > 20/24,B2 < 8/24))

    Just in case they are party animals and party til the break of dawn!

    Also if his doesn't work, I would definitely try putting MOD(cell,1) for every referenced cell. It seems like excel has dates connected to the times.
    Last edited by Green Crocodile; 08-26-2016 at 01:53 AM.

  10. #10
    Registered User
    Join Date
    08-25-2016
    Location
    London, England
    MS-Off Ver
    MS 2011
    Posts
    8

    Re: Problem counting times that occur between a fixed range that includes midnight

    Quote Originally Posted by Green Crocodile View Post
    In that case this will work.

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Phuocam has a awesome way of doing it too. One thing I would add to his formula (not even sure you will come across the scenario) is this...

    =IF(B2 < A2,B2 < 20/24,OR(A2 > 20/24,A2 < 8/24,B2 > 20/24,B2 < 8/24))

    Just in case they are party animals and party til the break of dawn!

    Also if his doesn't work, I would definitely try putting MOD(cell,1) for every referenced cell. It seems like excel has dates connected to the times.
    This solution worked beautifully. Thank you so much for taking the time to answer.

  11. #11
    Registered User
    Join Date
    08-18-2016
    Location
    Earth
    MS-Off Ver
    2010 and 2013
    Posts
    64

    Re: Problem counting times that occur between a fixed range that includes midnight

    You're welcome.

+ 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. Replies: 3
    Last Post: 08-17-2022, 11:21 AM
  2. Count the number of times a quantity of entries occur within a range
    By sameg in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-27-2015, 10:35 AM
  3. Replies: 5
    Last Post: 07-23-2014, 12:46 PM
  4. Replies: 8
    Last Post: 07-14-2013, 07:29 PM
  5. [SOLVED] counting how many times it occur
    By Elainefish in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 06-05-2013, 04:30 AM
  6. [SOLVED] Counting Cells that includes exact match and also if a cell includes specific text
    By smclachlan in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 08-19-2012, 07:42 PM
  7. Replies: 23
    Last Post: 08-17-2010, 04:22 PM

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