+ Reply to Thread
Results 1 to 14 of 14

Convert alpha-numeric code to date

  1. #1
    Registered User
    Join Date
    06-02-2012
    Location
    North Carolina
    MS-Off Ver
    Microsoft 365 Excel 2019 build 14430.20298
    Posts
    11

    Convert alpha-numeric code to date

    I need to convert several alpha-numeric codes into a month and year.

    The code format is as follows:

    DC22G02292

    The first character "D" is ignored. The second charater C represents the year and is defined as A=2007, B=2008, C=2009, D=2010, etc.

    The next two characters (22) stand for the week of the year. Charaters 5-10 are ignored.

    In this example the month and year would be May 2009.

    Is there a way to create a formula in Excel that will make this conversion?
    Last edited by Buchu; 06-02-2012 at 11:30 AM.

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

    Re: Convert alpha-numeric code to date

    A number of weeks straddle two months by various numbers of days. What are the rules for weeks relative to months?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  3. #3
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Convert alpha-numeric code to date

    I came up with this (assumes you want to start numbering weeks based on Jan 1 of year determined by 2nd character) - format result as mmm yy

    =DATE(1942+CODE(MID(A2,2,1)),1,1)+(MID(A2,3,2)-1)*7

  4. #4
    Registered User
    Join Date
    06-02-2012
    Location
    North Carolina
    MS-Off Ver
    Microsoft 365 Excel 2019 build 14430.20298
    Posts
    11

    Re: Convert alpha-numeric code to date

    The work week calendar vaires somewhat by year, but we can assume the following:


    January weeks 1-4
    February weeks 5-8
    March weeks 9-12
    April weeks 13-17
    May weeks 18-21
    June weeks 22-25
    July weeks 26-30
    August weeks 31-34
    Sepetember weeks 35-39
    October weeks 40-43
    November weeks 44-47
    December weeks 48-52

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

    Re: Convert alpha-numeric code to date

    At first, I thought you were using a 4-4-5 fiscal quarter method...but, evidently not.
    Try this:
    Please Login or Register  to view this content.
    Is that something you can work with?

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Convert alpha-numeric code to date

    Hi Buchu,

    I had your DC22G02292 in C18 - but I got June 2009 with your criteria:

    Please Login or Register  to view this content.

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  7. #7
    Registered User
    Join Date
    06-02-2012
    Location
    North Carolina
    MS-Off Ver
    Microsoft 365 Excel 2019 build 14430.20298
    Posts
    11

    Re: Convert alpha-numeric code to date

    Ron - looks like this is going to work just fine! I have one more step to go that is:

    I need to calculate the number of months between two different date formats. An example of the first format is :

    3/28/2008

    The second format is what we determined previousy, only a month and year:

    June 2010

    Is there an easy way to caluclate the number of months between 3/28/2008 and June 2010?

    Thanks!
    Last edited by Buchu; 06-02-2012 at 08:50 PM.

  8. #8
    Registered User
    Join Date
    06-02-2012
    Location
    North Carolina
    MS-Off Ver
    Microsoft 365 Excel 2019 build 14430.20298
    Posts
    11

    Re: Convert alpha-numeric code to date

    Quote Originally Posted by xladept View Post
    Hi Buchu,

    I had your DC22G02292 in C18 - but I got June 2009 with your criteria:

    Please Login or Register  to view this content.

    Please Login or Register  to view this content.
    Looks like this would work too! - need help running this in excel though.

  9. #9
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Convert alpha-numeric code to date

    Hi Buchu,

    You need to put the function in a standard module then you can use it just like any other Worksheet function.

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    06-02-2012
    Location
    North Carolina
    MS-Off Ver
    Microsoft 365 Excel 2019 build 14430.20298
    Posts
    11

    Re: Convert alpha-numeric code to date

    Quote Originally Posted by xladept View Post
    Hi Buchu,

    You need to put the function in a standard module then you can use it just like any other Worksheet function.

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Not sure what that means - do you have an example of how to do this?

  11. #11
    Forum Moderator vlady's Avatar
    Join Date
    09-22-2011
    Location
    Philippines - OLSHCO -Guimba-Nueva Ecija
    MS-Off Ver
    2021
    Posts
    4,361

    Re: Convert alpha-numeric code to date

    Hello Buchu

    right-click on the tab
    choose - view code
    in the window that will appear click insert menu - choose module
    thenpaste the code given above by xladept in the window.close.
    then you can use
    =MoYr(C18)

    btw save the workbook as macro-enabled workbook.
    I think people forget the word "THANK YOU!!!!" Do you still know it???

    There is a little star ( ADD REPUTATION ) below those person who helped you. Click it to say your "PRIVATE APPRECIATION TO THEIR EFFORT ON THEIR CONTRIBUTIONS "

    Regards,
    Vladimir

  12. #12
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Convert alpha-numeric code to date

    Hi Buchu,

    Normal View:

    Please Login or Register  to view this content.
    Formula View:


    Please Login or Register  to view this content.
    Does this work for you?

  13. #13
    Registered User
    Join Date
    06-02-2012
    Location
    North Carolina
    MS-Off Ver
    Microsoft 365 Excel 2019 build 14430.20298
    Posts
    11

    Re: Convert alpha-numeric code to date

    Quote Originally Posted by xladept View Post
    Hi Buchu,

    Normal View:

    Please Login or Register  to view this content.
    Formula View:


    Please Login or Register  to view this content.
    Does this work for you?
    Hi,

    Yes thats works thanks! I also discoverd the "DATEDIF" function

    =DATEDIF(A1,A2,"m")

    This function will subtract the two dates - you can have the result in days "d", months "m" or years "y". Try it out on your birthday to today's date to see how many months or days old you are. LOL!

  14. #14
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Convert alpha-numeric code to date

    Hi Buchu,

    Thanks for the function - Good Luck!

+ 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