5

I am attempting to extract a date stamp that is contained in one field and insert it into another field. The issue is that the date (in bold below) is not in the same location in each line of the data. I am able to find the location of the first "-", using python !fieldName!.find(-). Any ideas on how to complete the next step? I have thought about using a Mid function, but haven't been able to figure it out so far.


Data: ABCDE.ABCD-111611-43141 and ABCDEFG.ABCD-062914-95642

Here is what we came up with in the end:

Pre-Logic Script Code:

def ExtractDate(inValue):
 import string
 x= inValue.find('-')
 return inValue[x+1:x+7]

Field_Name =

ExtractDate( !MyFieldName! )
6

If all your data matches the format you posted, and all the numbers you want are in between the two dashes in the text (and those are the only dashes), you can use the split() method. Here's the code:

def extractText (yourTextField):
    partialText = yourTextField.split("-")
    return partialText[1]

That will split the input into 3 parts: the parts before the first dash, between the dashes, and after the second dash. Then it will return the second part.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.