+ Reply to Thread
Results 1 to 4 of 4

Unable to display Correct Text with Time reference

  1. #1
    Registered User
    Join Date
    03-13-2009
    Location
    London, England
    MS-Off Ver
    Excel 2016
    Posts
    98

    Unable to display Correct Text with Time reference

    Column B and C are opening and closing times of an exchange. For instance Product A exchange opens at 2300hrs and closes at 2140hrs the next day (or the exchange remains closed between 2140hrs and 2320hrs everday). Product B opens at 0710hrs and closes at 1620hrs. If the Time Now (Cell H1) is in between the opening and closing hours I would like to display that as "ON" in column D.

    I have tried combinations of AND and if functions along with subtracting times but no joy. Any help would be appreciated. Thansk
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Unable to display Correct Text with Time reference

    Try this formula;
    =IF(B2<C2,IF(AND(MOD($H$1,1)<C2,MOD($H$1,1)>B2),"ON","OFF"),IF(AND(MOD($H$1,1)>C2,MOD($H$1,1)<B2),"ON","OFF"))

    MOD($H$1,1) is needed because NOW() contains both time and date and you need the date (whole numbers) stripped off. Does that work for you?
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,993

    Re: Unable to display Correct Text with Time reference

    See attached. You have two problems.

    The biggest problem is that NOW() returns a date + time, not just time. I replaced it with a formula that provides just the time portion.

    The second problem is that you have intervals that start in one day and end the following day. That requires different arithmetic than when you start and stop the same day. See formulas that manage this.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,993

    Re: Unable to display Correct Text with Time reference

    I provided basically the same solution as ChemistB but I modified H1 instead of modifying the references to it.

    Gotta remember to hit Preview before posting

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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