+ Reply to Thread
Results 1 to 5 of 5

How To Check If Time Is Between Two Times In Excel?

  1. #1
    Registered User
    Join Date
    04-04-2020
    Location
    algeria
    MS-Off Ver
    2013
    Posts
    1

    Angry How To Check If Time Is Between Two Times In Excel?

    Hi
    I am tired of this
    I am looking for a function that performs the time
    You write a note like
    - breakfast. From 4:00 to 9:00
    - lunch time. From 11:00 to 14:00
    Dinner. From 19:00 to 23:00
    The function is valid, but its performance is not logical

    1.png

    IF BETWEN TO TIME.xlsx

  2. #2
    Forum Expert tim201110's Avatar
    Join Date
    10-23-2011
    Location
    Russia
    MS-Off Ver
    2016, 2019
    Posts
    2,357

    Re: How To Check If Time Is Between Two Times In Excel?

    =iferror(lookup(2,1/(c6>=$a$2:$e$2)/($a$1:$e$1>0)/(c6<=$b$2:$f$2)/($b$1:$f$1=0),$a$1:$e$1),"")

  3. #3
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,830

    Re: How To Check If Time Is Between Two Times In Excel?

    It is completely logical based on the formula you have created. You are telling Excel that if the time is not between the breakfast or lunch times, return dinner, so any time outside those periods will return dinner. You need to define the dinner period in the formula as another IF statement, and set "" as the value if false value.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  4. #4
    Forum Expert BMV's Avatar
    Join Date
    01-13-2020
    Location
    St-Petersburg, Russia
    MS-Off Ver
    2013-2016
    Posts
    1,329

    Re: How To Check If Time Is Between Two Times In Excel?

    Please Login or Register  to view this content.
    but be careful you have circuit reference in c6.
    And I know that 9:00 should be breakfast :-)
    Last edited by BMV; 04-04-2020 at 04:57 PM.

  5. #5
    Forum Expert
    Join Date
    05-01-2014
    Location
    California, US
    MS-Off Ver
    Excel 2010
    Posts
    1,795

    Re: How To Check If Time Is Between Two Times In Excel?

    @elokaz, you believe the results are incorrect because C6 displays the time 10:47, and the result is "dinner".

    You have made a couple of mistakes.

    -----

    First and foremost, you use NOW() in C6, which returns the date as well as time of day. So your formula in D6 would never have worked as intended, no matter how you might have tweaked it.

    Ostensibly, you should use MOD(NOW(),1) in order to "extract" just time of day.

    But really, you should use --TEXT(NOW(),"h:m"), which rounds to the second, then truncates to the minute, the same way that Excel displays time of day to the minute.

    The reason is: NOW() returns time of day to the 1/100 second. So, for example, if the current date and time is 4/4/2020 03:59:59.51, that displays the time as 04:00. But MOD(NOW(),1)>=TIME(4,0,0) returns FALSE, which might surprise you.

    -----

    Second, 10:47 does not fit between any of the three time frames.

    But in that case, your formula returns "dinner" because the time is not between 4:00-9:00 or 11:00-14:00.

    The remedy is to also test between 19:00-23:00 explicitly, and return the null string(?) if the time is not between that time frame as well.

    So your formula might be:
    Please Login or Register  to view this content.
    Note that there is no need to test C6<>"" separately, whether you use MEDIAN or AND with ">=" and "<=" operators.

    Caveat: When I retested that formula in a "new" instance of the downloaded file, the formula returns zero(!). Obviously, that is "impossible". I believe the problem arises because of the self-circular reference in C6. If I replace the formula in C6, then undo, the formula above returns the null string, as expected.

    The point is: The circular reference in C6 might cause problems with any valid solution.
    Last edited by joeu2004; 04-04-2020 at 07:40 PM.

+ 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: 9
    Last Post: 07-23-2019, 12:38 PM
  2. Replies: 1
    Last Post: 07-23-2019, 05:17 AM
  3. Replies: 3
    Last Post: 03-28-2018, 09:10 AM
  4. Check if a time is within two times (using first time as the starting time)
    By CraigsWorld in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-13-2017, 05:24 PM
  5. If a search term can be found 1 time, 2 times 3 times 4 times 5 times
    By excelcandy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-10-2013, 09:57 PM
  6. Check time is between 2 times and highlight cell
    By Tetley09 in forum Excel General
    Replies: 3
    Last Post: 10-17-2012, 07:46 AM
  7. Using Excel to check for overlapping times
    By evandp01 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-05-2012, 05:21 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