Select to view content in your preferred language

CalculateField - date field with Python expression

2081
2
06-16-2010 09:25 AM
SteveSalas
Frequent Contributor
I am writing a Python script that ultimately will be in a ArcGIS Server geoprocessing service.  A date field in a file GDB feature class needs to be populated with the current date.  Expression type must be Python according to the tool documentation because this will be a service (otherwise I'd be done by now with the VB expression "Date()"...).  My attempts have gone in circles for long enough - can anyone share a way to do this?

Thanks,
Steve
0 Kudos
2 Replies
KevinHibma
Esri Regular Contributor
Steve,

I'm not sure where you're going wrong exactly? Do you need Python syntax for time?

import time
print time.strftime("%Y/%m/%d %H:%M:%S", time.localtime())


Will give:
2010/06/11 11:34:14

Can you bring this into your calc script?
0 Kudos
SteveSalas
Frequent Contributor
Thanks, that was just the hint I needed - I don't think I tried YYYY/MM/DD in nested quotes...

gp.CalculateField_management("TEST_POLY","CREATE_DATE","'2007/01/01'","PYTHON_9.3")
0 Kudos