+ Reply to Thread
Results 1 to 7 of 7

Compare now() against two times

  1. #1
    Registered User
    Join Date
    09-30-2011
    Location
    Arizona, US
    MS-Off Ver
    Excel 2003
    Posts
    7

    Compare now() against two times

    Hi,

    I have a need to fill in a spreadsheet as time advances during the day every 15 minutes. So in column A, I simply created those time values (with a formatting of "time 13:30"), namely:

    8:00
    8:15
    8:30
    8:45

    In an adjacent column, I wish to take action if I'm between those time values. My formula isn't working, it is

    =IF(AND(NOW()>=A1,NOW()<A2),"Do 1","Do 2")

    Can you tell me how to fix this?

    Thanks

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Compare now() against two times

    If you want just the time, add MOD()

    e.g.

    =IF(AND(MOD(NOW(),1)>=A1,MOD(NOW(),1)<A2),"Do 1","Do 2")
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

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

    Re: Compare now() against two times

    Welcome to the Forum!

    NBVC has answered your question but I thought I would add some explanation around it.

    NOW() returns date + time. So for example, as I am typing this it returns

    9/30/2011 14:43

    and the underlying numeric value is 40816.613232. When you put in a time, you only get the decimal portion. For example, 08:00 has a value of 0.3333 (repeating) because it represents the fraction of a 24-hour day.

    So to compare NOW() to a time value you have to lop off the interest portion from NOW().

    As NBVC so concisely has done.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Registered User
    Join Date
    09-30-2011
    Location
    Arizona, US
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Compare now() against two times

    Wonderful, thanks NBVC, it works great.

    Thanks too 6StringJazzer, for explaining the underlying time format and why it works.

  5. #5
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Compare now() against two times

    apologies for the conciseness

  6. #6
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,627

    Re: Compare now() against two times

    You can use =NOW()-TODAY() or =NOW()-INT(NOW()) for example

  7. #7
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Compare now() against two times

    Those should both also work.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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