I have a created_date field in my (SDE) feature class. This selection by attributes statement works in ArcMap but I get an "Invalid Expression" error when trying to run it in arcpy. I have printed out the query and it looks to be probably formatted regarding quotations, but obviously I'm not typing it right and I wonder if I need to alter the "DatePart()" part of the formula.
countNumQuery <SPAN class="operator token">=</SPAN> <SPAN class="string token">"DatePart(''"</SPAN><SPAN class="string token">'yyyy'</SPAN><SPAN class="string token">"'', created_date) = {0} AND MonitoringPointID = '{1}'"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>countYear<SPAN class="punctuation token">,</SPAN> MPID<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>Prints like this:
DatePart("yyyy", created_date) = 2020 AND MonitoringPointID = '{4FE9BDAB-9EBB-4947-93E5-244170084B54}'
I've also tried this with no luck
<SPAN class="string token">"EXTRACT(YEAR FROM created_date) = {0} AND MonitoringPointID = '{1}'"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>countYear<SPAN class="punctuation token">,</SPAN> MPID<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>countYear is a integer. MonitoringPointID is a GUID. This works in ArcMap:
