Select to view content in your preferred language

calculate date-field with python

598
2
Jump to solution
09-26-2012 12:26 PM
MartinEgger
Occasional Contributor
Hi. I have a string-field (called 'unsplit') which contains concatenated values from other fields separated by a comma (example: 24.07.2010,street,...). I want to split/extract each commaseparated value and calculate it to a new field. I am using the field calculator and a pythonexpression. This expression works fine to calculate the value 'street' to a string-field: '!unsplit!.split(',')[1]
However, i can't calculate the value 24.07.2010 to a date-field using this expression: '!unsplit!.split(',')[0]
The error message is: <type 'exceptions.SyntaxError'>:EOL while scanning string literal.
What is wrong?
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
MathewCoyle
Honored Contributor
You'll need to make it a date object instead of a string I believe. Something like this maybe. (untested)

datetime.datetime.strptime('!unsplit!.split(',')[0], "%d.%m.%Y")

View solution in original post

0 Kudos
2 Replies
MathewCoyle
Honored Contributor
You'll need to make it a date object instead of a string I believe. Something like this maybe. (untested)

datetime.datetime.strptime('!unsplit!.split(',')[0], "%d.%m.%Y")
0 Kudos
MartinEgger
Occasional Contributor
Thanks a lot, Mathew.
It works fine. I was near a solution when I tested
datetime.strptime(!unsplit!.split(',')[0], "%d.%m.%Y")

before I posted that thread. It was missing one 'datetime' in the code.
0 Kudos