+ Reply to Thread
Results 1 to 5 of 5

Using "IF" with date returns an improper "FALSE"

  1. #1
    Valued Forum Contributor scaffdog845's Avatar
    Join Date
    02-01-2008
    Location
    Aston, PA. USA.
    MS-Off Ver
    Microsoft 365
    Posts
    375

    Using "IF" with date returns an improper "FALSE"

    Morning all,

    I'm trying to use an "IF" statement to look at a date in a cell and if it matches the criteria return the information from another cell. I have tried several different ways and constantly receive an improper "FALSE". Attached is a simplified example. I'm sure it's a simple soultion, but just the same I would appreciate the help.

    thanks
    Attached Files Attached Files
    Last edited by scaffdog845; 10-23-2008 at 10:55 AM. Reason: Solved

  2. #2
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561
    =IF(B2=DATE(2008,10,23),A2)

    Your formula asks: "is B2 (which is actually the number 39744 formatted to look like a date to you and me) the same as the string (i.e. the word) "10/23/08", which has a numeric value of 0?"

    39744 = "10/23/08"?
    The answer is no...

    You can use datevalue(string), e.g. datevalue("10/23/08") to coerce a string date to a true date, but date(<year>,<month>,<day>) as shown above, will cause fewer problems if you ever have to exchange information between Americans and people who choose to write dates out in the right order. For this reason alone I'd recommend the habit of using date() over datevalue() as good practice for the future.

    HTH

  3. #3
    Valued Forum Contributor scaffdog845's Avatar
    Join Date
    02-01-2008
    Location
    Aston, PA. USA.
    MS-Off Ver
    Microsoft 365
    Posts
    375
    Works great thank you. Every time I post I learn something new. One more quick question... How do I flag my post as being solved?

  4. #4
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Converting text to numbers.

    In your formula: =IF(B2="10/23/2008",A2)

    "10/23/2008" is text to Excel.
    However, you can coerce the text value to a number (date, in this case)
    by applying an arithmetic operator (+,-,/,*) to that text.

    The generally accepted convention for coercing text to numbers
    is to use a double-minus.

    Try this:
    Please Login or Register  to view this content.
    Does that help?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  5. #5
    Forum Contributor pr4t3ek's Avatar
    Join Date
    10-13-2008
    Location
    Melbourne, Australia
    MS-Off Ver
    2003 & 2007, 2010
    Posts
    483
    to mark a post as solved:

    1) Click the EDIT button on your first post
    2) Click the GO ADVANCED button
    3) Select SOLVED from the Title dropdown (under the Reason for Editing box)
    4) Click the SAVE CHANGES button
    --
    Regards
    PD

    ----- Don't Forget -----

    1. Use code tags. Place "[code]" before the first line of code and "[/code"]" after the last line of code. Exclude quotation marks

    2. Thank those who have helped you by Clicking the scales above each post.

    3. Please mark your post [SOLVED] if it has been answered satisfactorily.

+ 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