Wednesday, October 26, 2011

Working with Date Field (simple example)

Say you want to update a date field on a file geodatabase and it is in the format of: "Tue, 25 Oct 2011 18:44:39 +0000".  To insert this date, you need to convert it using the datetime module and provide the correct date format:
import datetime
def convertTime(timestring,format):
    return datetime.datetime.strptime(timestring, format)

where the format in this case would be "%a, %d %b %Y %H:%M:%S +0000".  You can then take the datetime object and insert the value into the date field.

You can find more on formatting times here in section 8.1.7.