<?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 build a whereClause with a datetime field in Python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-build-a-whereclause-with-a-datetime-field/m-p/132641#M10295</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This syntax seems to work too:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; whereClause = '"AGMID" =&amp;nbsp; %s AND "DIGIDATE" = date \'%s\' '&amp;nbsp; % (agreementID, datetimeVal)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 02 Mar 2016 17:44:50 GMT</pubDate>
    <dc:creator>JoseSanchez</dc:creator>
    <dc:date>2016-03-02T17:44:50Z</dc:date>
    <item>
      <title>How to build a whereClause with a datetime field in Python</title>
      <link>https://community.esri.com/t5/python-questions/how-to-build-a-whereclause-with-a-datetime-field/m-p/132639#M10293</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What is the syntax to use a date field in a whereClause?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This code does not work:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;datetimeVal = rowYesterday.getValue("DIGIDATE")&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;whereClause = "DateAGMT = " + datetimeVal&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ==============&amp;nbsp;&amp;nbsp; This syntax does not work&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;srcToday = arcpy.SearchCursor(AGREEMENT, whereClause)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 Mar 2016 15:26:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-build-a-whereclause-with-a-datetime-field/m-p/132639#M10293</guid>
      <dc:creator>JoseSanchez</dc:creator>
      <dc:date>2016-03-02T15:26:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to build a whereClause with a datetime field in Python</title>
      <link>https://community.esri.com/t5/python-questions/how-to-build-a-whereclause-with-a-datetime-field/m-p/132640#M10294</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jose,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You code above isn't working because it tries to concatenate values of two different types - a string and a datetime. You also need to explicitly tell the query that the value of datetimeVal is a datetime so that it gets read correctly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try this syntax: whereClause = "DateAGMT = date'{}'".format(datetimeVal)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One way to figure out the format for these queries (if Geonet isn't fast enough!) is to run a tool like Make Feature Layer with the same query you are trying to build. Dragging and dropping the result into the Python window in ArcMap or ArcCatalog will show you the syntax and .format will let you include variables in the query without worrying about variable types.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-Allison&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 Mar 2016 16:23:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-build-a-whereclause-with-a-datetime-field/m-p/132640#M10294</guid>
      <dc:creator>AllisonMuise1</dc:creator>
      <dc:date>2016-03-02T16:23:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to build a whereClause with a datetime field in Python</title>
      <link>https://community.esri.com/t5/python-questions/how-to-build-a-whereclause-with-a-datetime-field/m-p/132641#M10295</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This syntax seems to work too:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; whereClause = '"AGMID" =&amp;nbsp; %s AND "DIGIDATE" = date \'%s\' '&amp;nbsp; % (agreementID, datetimeVal)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 Mar 2016 17:44:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-build-a-whereclause-with-a-datetime-field/m-p/132641#M10295</guid>
      <dc:creator>JoseSanchez</dc:creator>
      <dc:date>2016-03-02T17:44:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to build a whereClause with a datetime field in Python</title>
      <link>https://community.esri.com/t5/python-questions/how-to-build-a-whereclause-with-a-datetime-field/m-p/132642#M10296</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jose,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Be sure to mark Allison's response as correct.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 Mar 2016 18:39:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-build-a-whereclause-with-a-datetime-field/m-p/132642#M10296</guid>
      <dc:creator>JacobTodd1</dc:creator>
      <dc:date>2016-03-02T18:39:05Z</dc:date>
    </item>
  </channel>
</rss>

