+ Reply to Thread
Results 1 to 10 of 10

Extracting date from string of numbers

  1. #1
    Registered User
    Join Date
    10-27-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    88

    Extracting date from string of numbers

    I am creating a sheet to flag up issues with products based on serial numbers, this is to flag up instances where a product has been returned for a fault after a modification has been made.

    The issue I have is that the serial number format has changed 3 times!

    DB1112506589 – first format (always starts with DB11, the next 2 digits are the year, the next 2 are the week, and the last 4 are the serial number)

    DB112506589 – second format (exactly the same as previous format but staring with DB1 instead of DB11 so the whole string is 1 digit less)

    T212126589 – third format (same as before except DB1 has been changed to T2, and now the date is indicated by year then month, instead of year then week)


    The bit causing me a headache is the fact that they had changed the part of the code that was previously indicated by a week to a month.

    What I am hoping to achieve is for us to be able to input any of the 3 types of serial numbers and for excel to automatically extract the data I need into the next cell, so we are essentially extracting the last 6 digits containing the date of production and the serial number, the problem being that for the first 2 types of number we need to convert the week to month (for instance week 03 would translate to month 01 and week 52 to month 12 etc)

    So is there a way for excel to work out which type is being input (we can easily identify this from the number of digits in the string) and then convert it accordingly?

  2. #2
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Extracting date from string of numbers

    when is week 1? how do you know which month a week is in?
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  3. #3
    Registered User
    Join Date
    10-27-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: Extracting date from string of numbers

    It is split into weeks of the year, so 1-52. Week 01-04 would be month 01.

  4. #4
    Forum Contributor
    Join Date
    08-02-2013
    Location
    Wageningen, The Netherlands
    MS-Off Ver
    365
    Posts
    495

    Re: Extracting date from string of numbers

    So you want the first and second format to be converted to the third format, right?

    To get you started, here's a formula to extract the month number from both the first and the second format. After that you need to round that number up, and work with functions like LEFT, RIGHT, MID and & to get the new format. Are you familiar with these functions i.e. can you do the rest yourself? Or do you need help with that, too?

    =IF(LEN(A3)=12,MID(A3,7,2)/52*12,MID(A3,6,2)/52*12)
    Where A3 is the cell with an old format in it
    When I say semicolon, u say comma!

  5. #5
    Forum Contributor
    Join Date
    08-02-2013
    Location
    Wageningen, The Netherlands
    MS-Off Ver
    365
    Posts
    495

    Re: Extracting date from string of numbers

    Quote Originally Posted by ormerods View Post
    It is split into weeks of the year, so 1-52. Week 01-04 would be month 01.
    That would result in a year with 13 months...

  6. #6
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,938

    Re: Extracting date from string of numbers

    extracting the year and week (or month), based on the SN is fairly easy using this...
    =MID(A1,LEN(A1)-7,2) (year)
    and
    =MID(A1,LEN(A1)-5,2) (week or month)

    What are you using to convert week to month (how would you normally do this - manually?)?

    edit: Looks like others are asking pretty much the same question lol
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  7. #7
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: Extracting date from string of numbers

    try

    =IF(LEN(A1)>10,TEXT(MIN(LEFT(RIGHT(A1,6),2)/4,12),"00")&RIGHT(A1,4),RIGHT(A1,6))
    Life's a spreadsheet, Excel!
    Say thanks, Click *

  8. #8
    Registered User
    Join Date
    10-27-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: Extracting date from string of numbers

    Quote Originally Posted by Ace_XL View Post
    try

    =IF(LEN(A1)>10,TEXT(MIN(LEFT(RIGHT(A1,6),2)/4,12),"00")&RIGHT(A1,4),RIGHT(A1,6))
    Thanks that seems to be what I need, wasn't exactly how I imagined doing it but this method will work better

    I may have made a slight error however when I gave you the example numbers, there should actually be an extra 2 digits on the end of the serial number, I have tried and tried but cannot figure out how your formula works to adjust it to take into account these 2 extra numbers! Can you help please?

    It would also be beneficial for me to display the 2 digits preceding the month (ie the year) is this possible?

  9. #9
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: Extracting date from string of numbers

    Try

    =LEFT(right(a1,10),2)&IF(LEN(A1)>12,TEXT(MIN(LEFT(RIGHT(A1,8),2)/4,12),"00")&RIGHT(A1,6),RIGHT(A1,8))

  10. #10
    Registered User
    Join Date
    10-27-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: Extracting date from string of numbers

    Thanks that works perfectly

+ 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. [SOLVED] extracting numbers from a string of text and numbers
    By ScottLor in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-05-2013, 04:47 PM
  2. Excel 2007 : Extracting Numbers from A String
    By pxoxyx in forum Excel General
    Replies: 6
    Last Post: 04-28-2010, 01:43 AM
  3. Extracting Numbers a from String
    By ratcat in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-25-2009, 11:13 AM
  4. [SOLVED] Extracting numbers of a string
    By Apaxe2000 in forum Excel General
    Replies: 4
    Last Post: 05-12-2006, 11:15 AM
  5. [SOLVED] extracting numbers from string
    By Chris Dowell via OfficeKB.com in forum Excel General
    Replies: 1
    Last Post: 01-12-2005, 06:06 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