<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to define a where clause for the 'date' data type in arcpy using cursor? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-define-a-where-clause-for-the-date-data/m-p/1087049#M61976</link>
    <description>If the installation date is coming from the lookup table, (I assume it’s like the last question you posted with the whereclause for the length?) it I’ll be in the correct datetime format if the field is already datetime type. If it’s a string, convert it to a datetime using datetime.strptime() and use it in your query.&lt;BR /&gt;&lt;BR /&gt;Your code here is passing ‘INSTALLATIONDATE’ as a string into the function instead of the assigned underlying value because you wrapped it in quotes in your method call.&lt;BR /&gt;</description>
    <pubDate>Mon, 09 Aug 2021 11:24:05 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2021-08-09T11:24:05Z</dc:date>
    <item>
      <title>How to define a where clause for the 'date' data type in arcpy using cursor?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-define-a-where-clause-for-the-date-data/m-p/1087042#M61973</link>
      <description>&lt;P&gt;Could anyone please help me, how to define a where clause for the date data type?. Currently using Arcmap 10.7.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;below is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;import arcpy&lt;BR /&gt;arcpy.env.workspace = "D:\\Maps and GDBs\NapervilleGas.gdb"&lt;BR /&gt;featureClass_1 = "P_Pipes"&lt;BR /&gt;Table_Pipe = "Pipe_Risk"&lt;BR /&gt;fieldNames_1 = [ "Material" , "OPERATINGPRESSURE" , "MEASUREDLENGTH" , "INSTALLATIONDATE", "Risk_Score"]&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;BR /&gt;fieldNames = ["Material" , "OPERATINGPRESSURE" , "MEASUREDLENGTHLOWERLIMIT" ,"MEASUREDLENGTHUPPERLIMIT" , "INSTALLATIONDATELOWERLIMIT" , "INSTALLATIONDATEUPPERLIMIT" , "OVERALLRISKSCORE"]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;def Pipe_Risk_Score(INSTALLATIONDATE):&lt;/P&gt;&lt;P&gt;ID_Out_fields = ["INSTALLATIONDATELOWERLIMIT" , "INSTALLATIONDATEUPPERLIMIT" , "OVERALLRISKSCORE"]&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;ID_where_Clause = "(INSTALLATIONDATELOWERLIMIT &amp;lt;= {} and INSTALLATIONDATEUPPERLIMIT &amp;gt;= {})".format(INSTALLATIONDATE)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Table_Pipe_Cursor = arcpy.da.SearchCursor(Table_Pipe, ID_Out_fields, ID_where_Clause)&lt;/P&gt;&lt;P&gt;for row in Table_Pipe_Cursor:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; lst.append(row[2])&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; ID_Risk_Score = row[2]&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; print (ID_Risk_Score)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Pipe_Risk_Score("INSTALLATIONDATE")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Aug 2021 10:27:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-define-a-where-clause-for-the-date-data/m-p/1087042#M61973</guid>
      <dc:creator>broy06</dc:creator>
      <dc:date>2021-08-09T10:27:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to define a where clause for the 'date' data type in arcpy using cursor?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-define-a-where-clause-for-the-date-data/m-p/1087049#M61976</link>
      <description>If the installation date is coming from the lookup table, (I assume it’s like the last question you posted with the whereclause for the length?) it I’ll be in the correct datetime format if the field is already datetime type. If it’s a string, convert it to a datetime using datetime.strptime() and use it in your query.&lt;BR /&gt;&lt;BR /&gt;Your code here is passing ‘INSTALLATIONDATE’ as a string into the function instead of the assigned underlying value because you wrapped it in quotes in your method call.&lt;BR /&gt;</description>
      <pubDate>Mon, 09 Aug 2021 11:24:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-define-a-where-clause-for-the-date-data/m-p/1087049#M61976</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-08-09T11:24:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to define a where clause for the 'date' data type in arcpy using cursor?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-define-a-where-clause-for-the-date-data/m-p/1087055#M61981</link>
      <description>&lt;P&gt;I posted this on your other question, its relevant here too.&lt;/P&gt;&lt;P&gt;You are passing strings into your functions:&lt;/P&gt;&lt;PRE&gt;Pipe_Risk_Score("INSTALLATIONDATE")&lt;/PRE&gt;&lt;P&gt;&lt;SPAN class="hljs-string"&gt;INSTALLATIONDATE is assigned "INSTALLATIONDATE" and your whereclause is:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="hljs-string"&gt;"INSTALLATIONDATELOWERLIMIT &amp;lt;= 'INSTALLATIONDATE' and INSTALLATIONDATEUPPERLIMIT &amp;gt;= 'INSTALLATIONDATE'"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;If you want the float / date that is assigned to MEASUREDLENGTH (or any of the other values), you need to remove the quotes in the function call so it passes the variables and not&amp;nbsp; &lt;SPAN class="hljs-string"&gt;"INSTALLATIONDATE"&lt;/SPAN&gt; strings. For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;INSTALLATIONDATE = datetime.strptime('08/03/2021 12:43:34')

Pipe_Risk_Score(INSTALLATIONDATE)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="hljs-string"&gt;INSTALLATIONDATE is assigned datetime 08/03/2021 12:43:34&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="hljs-string"&gt;"INSTALLATIONDATELOWERLIMIT &amp;lt;= datetime(08/03/2021 12:43:34) and INSTALLATIONDATEUPPERLIMIT &amp;gt;= datetime(08/03/2021 12:43:34)"&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Aug 2021 11:45:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-define-a-where-clause-for-the-date-data/m-p/1087055#M61981</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-08-09T11:45:24Z</dc:date>
    </item>
  </channel>
</rss>

