Hello everyone,
how can I add a date field in a whereClause when using an arcpy.SearchCursor?
This is the portion of the code I am using:
for row in cur:
whereClause = "AGMID = " + row.getValue("AGMID") + " AND DIGIDATE = " + row.getValue("DIGIDATE")
src = arcpy.SearchCursor(AGREEMENT, whereClause)
I can compare the field "AGMID = " + row.getValue("AGMID") but the field DIGIDATE fails.
Thanks
can't tell without the actual data but try .... str(row.getValue("DIGIDATE") assuming that is how you access the date, perhaps you need to concatenate strings and the getvalue isn't returning a string
Do not try to nest old style cursors - they get confused. Instead, nest data access module cursors. Or, better yet, find a way around nesting cursors, like loading the contents of one cursor into a dictionary and referencing those values from the second cursor.
For more information on Darren's suggestion to load the contents of a cursor into a dictionary, Richard Fairhurst has a good blog on the topic.
Turbo Charging Data Manipulation with Python Cursors and Dictionaries
I realized that my question is more general.
How can I use a date field in a whereClause that I can reuse in a arcpy.SearchCursor?
Also what is the difference between arcpy.da.SearchCursor and arcpy.SearchCursor?
Thanks
How can I use a date field in a whereClause that I can reuse in a arcpy.SearchCursor?
That will depend on the geodatabase (file, personal, SQL Server, Oracle, etc)
SQL reference for query expressions used in ArcGIS—Help | ArcGIS for Desktop
what is the difference between arcpy.da.SearchCursor and arcpy.SearchCursor?
Accessing data using cursors—Help | ArcGIS for Desktop
A new data access module (arcpy.da) was added in ArcGIS 10.1. The previously existing cursors (that are still listed under arcpy) are still functional and valid; however, the new arcpy.da cursors include significantly faster performance. In most cases, the help will illustrate the use of the arcpy.da cursors.
Hi, do you get the answer for the first part? As per me, arcpy.da.SearchCursor basically means we're accessing the data for the further use like update & all whereas arcpy.SearchCursor is also the same as arcpy.da.SearchCursor. So, both the things are same. Could you please tell me the answer for the first part "Use of date field data type"?
Regarding:
So, both the things are same.
Outside of arcpy.SearchCursor and arcpy.da.SearchCursor both being search cursors, the two types of cursors are nothing alike in terms of implementation and performance. See the response/answer from Jason Scheirer on arcpy - How is the data access cursor performance so enhanced compared to previous versions? - Geogr....