AnsweredAssumed Answered

Python arcpy.GetParameterAsText() for a Date field

Question asked by jsn on May 7, 2018
Latest reply on May 7, 2018 by Dan_Patterson

Hello everyone,


This is my first Geoprocessing Service based on a Python script tool.. How do I process a datetime field in a Python script tool?


I wrote a Python script tool and one of the parameter fields gets a DateTime value. This field fails with the following error message.


Python tool Parameters (Properties --> Parameters)

  • RequestedDate   Date
  • Rest of parameters are numeric or text fields


Python source Code:

in_requesteddate = arcpy.GetParameterAsText(5)

arcpy.AddMessage("in_requesteddate = " + in_requesteddate)

in_featureclass = arcpy.GetParameter(6)

requested_datetime = datetime.strptime(in_requesteddate, '%m/%d/%Y')




Error Message:

Traceback (most recent call last):
  File "C:\Workspace\GeocoprocessingServices\Sample\", line 25, in <module>
AttributeError: 'module' object has no attribute 'strptime'



Is this field processed as a text field or as a DateTime field? 

Do I need this conversion datetime.strptime .....