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! )
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Sep 29, 2014 at 21:39

1 Answer 1

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.

answered Sep 29, 2014 at 22:07

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.