+ Reply to Thread
Results 1 to 7 of 7

Changing date format in formula

  1. #1
    Forum Contributor
    Join Date
    01-05-2010
    Location
    New York
    MS-Off Ver
    Excel 2016
    Posts
    747

    Changing date format in formula

    I have the following formula where $B$5 is a date in the format mm/dd/yyyy. The formula is matching the date value in $B$5 with the date values in $Z$4:$Z$1000. The problem is that the date values in $Z$4:$Z$1000 are in the format mm/dd/yyyy hh:mm:ss am/pm so no matches are found. How can I change the formula to find an appropriate match if the mm/dd/yyyy are the same?



    =IFERROR(INDEX('Enter Executions'!$C$4:$C$1000,SMALL(IF('Enter Executions'!$B$4:$B$1000=$B$4,IF('Enter Executions'!$Z$4:$Z$1000=$B$5,ROW('Enter Executions'!$B$4:$B$1000)-ROW('Enter Executions'!$B$4)+1)),ROWS($A$1:$A1))),"")
    Last edited by rhudgins; 03-29-2011 at 11:19 AM.

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

    Re: Changing date format in formula

    Excel doesn't look at the format. If one cell is formatted as dd/mm/yy and the other as mm/dd/yy, Excel just sees the underlying number. What is probably happening in your case is that one of the two ranges is formatted as text and the other as number (or both are formatted as text). To check, (let's say your date is in A1), in a blank cell, type =ISNUMBER(A1). If it's true, it's a number.
    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
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Changing date format in formula

    You can extract a date from a date/time using INT function, so try replacing this part

    'Enter Executions'!$Z$4:$Z$1000

    with

    INT('Enter Executions'!$Z$4:$Z$1000)
    Audere est facere

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

    Re: Changing date format in formula

    Ahhh, reread your original post. Because you have hours on the one range, that will cause them not to match.

    Whenever referring to your data in Z, use INT to truncate the hours and minutes
    i.e.
    INT('Enter Executions'!$Z$4:$Z$1000)=$B$5

  5. #5
    Forum Contributor
    Join Date
    01-05-2010
    Location
    New York
    MS-Off Ver
    Excel 2016
    Posts
    747

    Re: Changing date format in formula

    I tried changing it to IF(INT('Enter Executions'!$Z$4:$Z$1000)=$B$5 and I recieved an error. Any ideas what I am doing wrong?


    {=IFERROR(INDEX('Enter Executions'!$C$4:$C$1000,SMALL(IF('Enter Executions'!$B$4:$B$1000=$B$4,IF(INT('Enter Executions'!$Z$4:$Z$1000=$B$5,ROW('Enter Executions'!$B$4:$B$1000)-ROW('Enter Executions'!$B$4)+1)),ROWS($A$1:$A1))),"")}
    Last edited by rhudgins; 03-28-2011 at 05:09 PM.

  6. #6
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Changing date format in formula

    It might depend on what you have in that range - INT will cause an error if applied to a text value, for instance. An alternative approach (which won't give an error in those circumstances) is to check that the Z range contains a value >=B5 but < B5+1, i.e. it's on that day......

    =IFERROR(INDEX('Enter Executions'!$C$4:$C$1000,SMALL(IF('Enter Executions'!$B$4:$B$1000=$B$4,IF('Enter Executions'!$Z$4:$Z$1000>=$B$5,IF('Enter Executions'!$Z$4:$Z$1000<$B$5+1,ROW('Enter Executions'!$B$4:$B$1000)-ROW('Enter Executions'!$B$4)+1))),ROWS($A$1:$A1))),"")

    confirmed with CTRL+SHIFT+ENTER as before

  7. #7
    Forum Contributor
    Join Date
    01-05-2010
    Location
    New York
    MS-Off Ver
    Excel 2016
    Posts
    747

    Re: Changing date format in formula

    Thanks this solutions works well.

+ 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