+ Reply to Thread
Results 1 to 8 of 8

Convert text to date

  1. #1
    Registered User
    Join Date
    02-09-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    3

    Convert text to date

    Hi there,

    I need help converting several rows of text to dates.

    For example, I have several cells in column A with text 'mmm dd yyyy' (i.e. Feb 22 2011). I need to add this data to a report with several dates but obviously when I sort the data the text dates are sorted alphabetically and the dates are sorted in date order which is no good to me. I need the report all in date order.

    Does anyone know of a simple formula to convert this text format (mmm dd yyyy) into a date format such 22/02/2011?

    Thanking you in advance,

    Matt

  2. #2
    Forum Expert
    Join Date
    12-03-2009
    Location
    Florence, Italy
    MS-Off Ver
    Excel 2019
    Posts
    1,796

    Re: Convert text to date

    Hi, I'm translating the formula from a Italian Excel. I hope it could do its job.

    =DATE(RIGHT(A1,4)+0,VLOOKUP(LEFT(A1,3),{"Jan",1\"Feb",2\"Mar",3\"Apr",4\"May",5\"Jun",6\"Jul",7\"Aug",8\"Sep",9\"Oct",10\"Nov",11\"Dec",12},2,0),MID(A1,5,2)+0)
    Regards
    Attached Files Attached Files
    Last edited by canapone; 02-22-2011 at 09:15 AM.

  3. #3
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561

    Re: Convert text to date

    I couldn't understand exactly what you were trying to do Canapone, but I'm afraid it doesn't work in my version of Excel.

    Matt, try:
    =DATEVALUE(MID(A1,5,3)&LEFT(A1,4)&RIGHT(A1,4))

    NB we prefer here if thread starters acknowledge replies (ideally reflecting the time someone else spent helping them)
    Last edited by Cheeky Charlie; 02-22-2011 at 10:27 AM.
    CC


    If you feel really indebted please consider a donation to charity. My preferred charity is ActionAid but there are plenty of worthy alternatives.

  4. #4
    Forum Expert
    Join Date
    12-03-2009
    Location
    Florence, Italy
    MS-Off Ver
    Excel 2019
    Posts
    1,796

    Re: Convert text to date

    Hi, translating from Italian Excel I've inverted the slash with the coma in the VLOOKUP segment.

    This is my second try, I hope to have more luck

    =DATE(RIGHT(A1,4)+0,VLOOKUP(LEFT(A1,3),{"Jan"\1,"Feb"\2,"Mar"\3,"Apr"\4,"May"\5,"Jun"\6,"Jul"\7,"Aug"\8,"Sep"\9,"Oct"\10,"Nov"\11,"Dec"\12},2,0),MID(A1,5,2)+0)
    I was trying a very simple

    =Date(year,month,day)

    I had no problem to extract and make it read years and days to DATE formula.

    To translate Jan/Feb/Mar … into numbers I wrote a table of correspondences (Jan = 1; Feb = 2; ….) in G1:H12 and I’ve used a VLOOKUP


    VLOOKUP(LEFT(A1,3),G1:H12,2,0) as second argument of DATE

    I've highlighted the second argument of VLOOKUP G1:H12 from the formula bar , press F9 to translate/explicit (sorry: I don't know the correct expression to describe this use of command F9) my table into the formula in order to unplug VLOOKUP from reading G1:H12.

    Regards
    Last edited by canapone; 02-22-2011 at 01:13 PM. Reason: very poor grammar

  5. #5
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561

    Re: Convert text to date

    In English Excel:
    =DATE(RIGHT(A1,4),VLOOKUP(LEFT(A1,3),{"Jan",1;"Feb",2;"Mar",3;"Apr",4;"May",5;"Jun",6;"Jul",7;"Aug ",8;"Sep",9;"Oct",10;"Nov",11;"Dec",12},2,0),MID(A1,5,2))

    NB you don't have to coerce the arguments of date (i.e. the +0 bit) - date will coerce numbers entered as text.

  6. #6
    Forum Expert
    Join Date
    12-03-2009
    Location
    Florence, Italy
    MS-Off Ver
    Excel 2019
    Posts
    1,796

    Re: Convert text to date

    Hi Charlie,

    thank you very much, I'm learning a great deal from the Forum.

    Regards

  7. #7
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561

    Re: Convert text to date

    I think I prefer the way datevalue can turn a string into a date without having to use any kind of lookup - that said, if you are going to use a lookup this is perhaps a bit neater:

    =MATCH(A1,{"jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"},0)

    I don't envy you learning Excel whilst having to deal with transliteration issues.

  8. #8
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Convert text to date

    FWIW, another slightly shorter alternative for getting a month number from a mmm string is to use:

    Please Login or Register  to view this content.
    where A1 holds "Jan" etc...

+ 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