+ Reply to Thread
Results 1 to 4 of 4

Verifying if a time falls within a range

  1. #1
    Registered User
    Join Date
    02-16-2012
    Location
    texas
    MS-Off Ver
    Excel 2003
    Posts
    2

    Verifying if a time falls within a range

    Excel 2003

    I'm trying to verify whether a certain stock traded in a day. I have a data feed that either inputs a time if it traded today or a date if it didn't. I also need to make sure the time falls within this range because I can't use the price if falls outside of normal market hours.

    I'm using
    =IF(OR(N10>"9:00:00 AM",N10<"4:31:00 PM"),N10,"NONE TODAY")

    Currently this is returning the time. If I manually change the reference cell to a date, then excel is putting out a number. If I change the OR function to AND, then the cell returns none today.

    I'm open to other ways to get either a true or false value.

    Thanks in Advance.

  2. #2
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,064

    Re: Verifying if a time falls within a range

    That OR should definitely be an AND
    something like

    =IF(AND(N10>TIMEVALUE("09:00:00"),N10<TIMEVALUE("16:31:00"),N10,"NONE TODAY")
    Regards
    Special-K

    Ensure you describe your problem clearly, I have little time available to solve these problems and do not appreciate numerous changes to them.

  3. #3
    Registered User
    Join Date
    02-16-2012
    Location
    texas
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Verifying if a time falls within a range

    Quote Originally Posted by Special-K View Post
    That OR should definitely be an AND
    something like

    =IF(AND(N10>TIMEVALUE("09:00:00"),N10<TIMEVALUE("16:31:00"),N10,"NONE TODAY")
    Just tried that and it returns "None Today" which is incorrect as all the securities I'm looking at today did trade within the range I need.

    The cell I'm looking at currently has 4:15:04 PM in it
    Last edited by kckid816; 02-16-2012 at 05:18 PM.

  4. #4
    Registered User
    Join Date
    02-03-2012
    Location
    Morrisville, North Carolina (USA)
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Verifying if a time falls within a range

    Something else to consider, what is the value in N10 really? In excel everything is really a number, dates and times are just formatting of those numbers. Times are never really just times, there are always dates associated whether you realize it or not. When you use TIMEVALUE("09:00:00") you are setting the value to "01/00/1900 09:00:00 AM". The value in cell N10 is most likely a Date/Time that is formatted to display only the time (change the cell format on N10 to one of the date/time styles and you will see what is really there). This is probably why the formula isn't working. The 4:15:04PM is really "2/27/2012 4:15:04PM" which is > "01/00/1900 09:00:00 AM" but is not < "01/00/1900 04:31:00 PM" therefore your conditional statement is false.

    Here are some workarounds that should do the trick...

    If you simply want to use time and your data is always for today with different times:
    =IF(AND(MOD(N10,1)>TIMEVALUE("09:00:00"),MOD(N10,1)<TIMEVALUE("16:31:00"),N10,"NONE TODAY")

    The MOD (modulo) function takes the date time in N10 (which is really a number where the portion ahead of the decimal is the date and the portion after the decimal is the time) and returns only the remainder (time portion) of it setting the date to 1/0/1900 just like your TIMEVALUE function putting your math back in parity. It's a handy way to convert date/time to time only for calculations like these.

    If you had several days worth of data and wanted only the cells that were for today's date and between those times you could use:
    =IF(AND(N10>TODAY()+TIMEVALUE("09:00:00"),N10<TODAY()+TIMEVALUE("16:31:00"),N10,"NONE TODAY")

+ 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