+ Reply to Thread
Results 1 to 24 of 24

Check if time range is within another time range

Hybrid View

  1. #1
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,765

    Re: Check if time range is within another time range

    A
    B
    C
    D
    1
    Result should be
    formula
    2
    15:00-16:00 08:00-16:00
    1
    1
    3
    16:00-17:00 08:00-16:00
    0
    0
    4
    17:00-18:00 08:00-16:00
    0
    0
    5
    6
    Result should be
    7
    15:00-16:00 17:00-01:00
    0
    0
    8
    16:00-17:00 17:00-01:00
    0
    0
    9
    17:00-18:00 17:00-01:00
    1
    1


    A
    B
    C
    D
    2
    15:00-16:00 08:00-16:00
    1
    =LET(
    startTime1,FILTERXML("<x><y>"&SUBSTITUTE(A2,"-","</y><y>")&"</y></x>","//y[1]"),
    endTime1,FILTERXML("<x><y>"&SUBSTITUTE(A2,"-","</y><y>")&"</y></x>","//y[2]"),
    startTime2,FILTERXML("<x><y>"&SUBSTITUTE(B2,"-","</y><y>")&"</y></x>","//y[1]"),
    endTime2,FILTERXML("<x><y>"&SUBSTITUTE(B2,"-","</y><y>")&"</y></x>","//y[2]"),
    IF(endTime2>startTime2,IF(AND(startTime2<=startTime1,endTime2>=endTime1),1,0),IF(AND(startTime2<=startTime1,endTime2+"24:00:00">=endTime1),1,0)))
    3
    16:00-17:00 17:00-01:00
    0
    =LET(
    startTime1,FILTERXML("<x><y>"&SUBSTITUTE(A3,"-","</y><y>")&"</y></x>","//y[1]"),
    endTime1,FILTERXML("<x><y>"&SUBSTITUTE(A3,"-","</y><y>")&"</y></x>","//y[2]"),
    startTime2,FILTERXML("<x><y>"&SUBSTITUTE(B3,"-","</y><y>")&"</y></x>","//y[1]"),
    endTime2,FILTERXML("<x><y>"&SUBSTITUTE(B3,"-","</y><y>")&"</y></x>","//y[2]"),
    IF(endTime2>startTime2,IF(AND(startTime2<=startTime1,endTime2>=endTime1),1,0),IF(AND(startTime2<=startTime1,endTime2+"24:00:00">=endTime1),1,0)))
    Happy with my answer * Add Reputation.
    If You are happy with solution, please use Thread tools and mark thread as SOLVED.

  2. #2
    Registered User
    Join Date
    09-20-2021
    Location
    Netherlands
    MS-Off Ver
    O365
    Posts
    11

    Re: Check if time range is within another time range

    Hi Kokosek,

    Thank you so much for your reply!

    I have taken the if statement and instead used LEFT RIGHT for the start and end time. I had to add IFERROR as well because when a cell is empty it throw me a #VALUE. This works like a charm.

    There is only 1 issue I'm facing and that's that my formula is very long and I would need to check multiple rows with the same formula in 1 cell so I do a + and the same formula again changing the row numbers.

    Example is attached.

    This is the formula:

    =IF(ISNUMBER(SEARCH("*Test*";$A$2));IF(IFERROR(VALUE(RIGHT(C$2;5))>VALUE(LEFT(C$2;5)););IF(IFERROR(AND(VALUE(LEFT(C$2;5))<=VALUE(LEFT($B13;5));VALUE(RIGHT(C$2;5))>=VALUE(RIGHT($B13;5))););1;0);IF(IFERROR(AND(VALUE(LEFT(C$2;5))<=VALUE(LEFT($B13;5));VALUE(RIGHT(C$2;5))+"24:00:00">=VALUE(RIGHT($B13;5))););1;0)))

    And when I want to check the new row I add + and the same formula and change the row number on column A and C

    +IF(ISNUMBER(SEARCH("*Test*";$A$3));IF(IFERROR(VALUE(RIGHT(C$3;5))>VALUE(LEFT(C$3;5)););IF(IFERROR(AND(VALUE(LEFT(C$3;5))<=VALUE(LEFT($B13;5));VALUE(RIGHT(C$3;5))>=VALUE(RIGHT($B13;5))););1;0);IF(IFERROR(AND(VALUE(LEFT(C$3;5))<=VALUE(LEFT($B13;5));VALUE(RIGHT(C$3;5))+"24:00:00">=VALUE(RIGHT($B13;5))););1;0)))

    Is there any way to shorten this formula or how to repeat it without having to write the whole formula with a +
    Attached Files Attached Files

+ 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: 1
    Last Post: 07-23-2019, 11:09 AM
  2. Replies: 2
    Last Post: 06-26-2018, 09:10 PM
  3. [SOLVED] Check if range of time falls in another range of time
    By wafs in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 06-18-2018, 06:47 PM
  4. Check if event occurs within time range
    By excellinginlife in forum Excel Formulas & Functions
    Replies: 17
    Last Post: 09-20-2016, 10:43 AM
  5. [SOLVED] Counting values in a time range - when the time range crosses midnight
    By dlocos in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-24-2014, 04:27 AM
  6. Replies: 4
    Last Post: 08-04-2011, 03:54 PM
  7. Check value in a time range
    By badin in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 02-25-2008, 06:31 PM

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