+ Reply to Thread
Results 1 to 9 of 9

Problem converting text to Excel date using LEFT and SUBSTITUTE

  1. #1
    Forum Contributor
    Join Date
    12-03-2008
    Location
    Key West, FL
    MS-Off Ver
    365 Apps for Enterprise
    Posts
    665

    Problem converting text to Excel date using LEFT and SUBSTITUTE

    I've attached a workbook showing two rows of "text" dates which I then attempt to convert to Excel date.

    Visually, the text date in row 2 appears to be formatted exactly the same as the date in row 3.

    However my formula (which I have spread out into some helper cells) works for row 2 but not row 3.

    I can't figure out why it's "breaking." I've tried using "CLEAN" in case there are hidden characters I can't see, but that doesn't work.

    Any thoughts? Thank you!
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    09-07-2014
    Location
    Israel
    MS-Off Ver
    office 365 for MAC
    Posts
    3,138

    Re: Problem converting text to Excel date using LEFT and SUBSTITUTE

    There is no difference.
    both produce a result.
    Attached Files Attached Files

  3. #3
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    16,064

    Re: Problem converting text to Excel date using LEFT and SUBSTITUTE

    What result do you expect? Are these supposed to be dates in February?

    In my copy of Excel (where the regional settings are using the standard US date format of month/day/year), It reads row 2 as 2 Dec 2018. But, Excel doesn't know what to do with "month 14" in row 3, so the DATEVALUE() function returns an error.

    I suspect that, if your regional settings are European (day/month/year), Excel would interpret these dates as 12 and 14 February 2018.

    The DATEVALUE() function looks at your systems regional settings to decide how to interpret text dates. The error is probably because Excel cannot use your regional settings to correctly interpret these date strings. The solution depends on whether you want to change your regional settings or change how you approach the string to date conversion.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  4. #4
    Forum Contributor
    Join Date
    12-03-2008
    Location
    Key West, FL
    MS-Off Ver
    365 Apps for Enterprise
    Posts
    665

    Re: Problem converting text to Excel date using LEFT and SUBSTITUTE

    Thank You MrShorty. Yes the month is February, and I think you're right because in the actual workbook (much larger) the formulas work during every month up through the 12th day, then it breaks.

    I would have thought that this problem could be rectified by using a custom date format to "figure out" the datevalue, but so far I haven't come up with a solution. In my actual workbook, I do further calculations based on date, so the date cell will have dependencies.

    Hmm.... maybe I could use the LEFT and RIGHT formulas to isolate the day, month and year, then CONCAT to rearrange them, then convert to DATEVALUE?

  5. #5
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,415

    Re: Problem converting text to Excel date using LEFT and SUBSTITUTE

    How about
    =DATE(MID(A2,7,4),MID(A2,4,2),LEFT(A2,2))

  6. #6
    Forum Contributor
    Join Date
    12-03-2008
    Location
    Key West, FL
    MS-Off Ver
    365 Apps for Enterprise
    Posts
    665

    Re: Problem converting text to Excel date using LEFT and SUBSTITUTE

    Yes, that works! Thank you everyone. Stay safe!

  7. #7
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,432

    Re: Problem converting text to Excel date using LEFT and SUBSTITUTE

    Quote Originally Posted by jrtaylor View Post
    Yes the month is February, and I think you're right because in the actual workbook (much larger) the formulas work during every month up through the 12th day, then it breaks.
    Given your formula breaks when what you consider the day is greater than 12, then I suspect that your formula is not working correctly at all. For the dates that your formula is returning a date, I suspect that your formula is using what you think is the month as the day value and what you think is the day as the month value to create the displayed date... you should check the converted dates against what date you think the text date is supposed to represent (formatting the cell to show the month name should help you see what I am referring to).
    Last edited by Rick Rothstein; 06-29-2020 at 05:23 PM.

  8. #8
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,415

    Re: Problem converting text to Excel date using LEFT and SUBSTITUTE

    Glad we could help & thanks for the feedback.

  9. #9
    Forum Contributor
    Join Date
    12-03-2008
    Location
    Key West, FL
    MS-Off Ver
    365 Apps for Enterprise
    Posts
    665

    Re: Problem converting text to Excel date using LEFT and SUBSTITUTE

    Quote Originally Posted by Rick Rothstein View Post
    Given your formula breaks when what you consider the day is greater than 12, then I suspect that your formula is not working correctly at all. For the dates that your formula is returning a date, I suspect that your formula is using what you think is the month as the day value and what you think is the day as the month value to create the displayed date... you should check the converted dates against what date you think the text date is supposed to represent.
    Thanks Rick, yes I hadn't picked that up, but will fix that using Fluff's idea.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Substitute function problem- Numeric as Text-Need to have those as Number
    By punno2015 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-29-2019, 11:54 AM
  2. Date Problem Converting PDF to Excel
    By Kellbells in forum Excel General
    Replies: 6
    Last Post: 12-16-2014, 05:25 PM
  3. Replies: 1
    Last Post: 12-20-2012, 12:28 PM
  4. problem converting multiple text files into excel worksheets macro
    By mehdoush in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 05-19-2012, 03:51 AM
  5. Excel Date - Converting to Text?
    By heatwave in forum Excel General
    Replies: 3
    Last Post: 07-20-2010, 12:28 AM
  6. Excel keeps converting to DATE, when I want text
    By Psy6 in forum Excel General
    Replies: 10
    Last Post: 05-27-2008, 03:17 AM
  7. [SOLVED] Excel keeps converting text to date format
    By John T via OfficeKB.com in forum Excel General
    Replies: 4
    Last Post: 09-12-2005, 02:05 PM

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