<?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 do I ensure accurate date selection within script tool? in Developers Questions</title>
    <link>https://community.esri.com/t5/developers-questions/how-do-i-ensure-accurate-date-selection-within/m-p/626950#M4219</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It sorts as I would expect, by month and day.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 26 Oct 2016 18:13:22 GMT</pubDate>
    <dc:creator>KarlKeough</dc:creator>
    <dc:date>2016-10-26T18:13:22Z</dc:date>
    <item>
      <title>How do I ensure accurate date selection within script tool?</title>
      <link>https://community.esri.com/t5/developers-questions/how-do-i-ensure-accurate-date-selection-within/m-p/626948#M4217</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="margin: 0in 0in 0pt;"&gt;&lt;SPAN style="color: black;"&gt;I have created a script tool that will ask a user to select start and end dates within which records will be selected from a feature class. The field containing the dates is formatted as type Date. I want to use those dates within an sql query to select the records, which requires that they be formatted as dates, but the GetParameterAsText command converts the user selection to a string, which means I have to convert back to date in the code. The code I am using is as follows: &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0in 0in 0pt;"&gt;&lt;SPAN style="color: black;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0in 0in 0pt;"&gt;&lt;SPAN style="color: black;"&gt;#get start and end dates for report generation&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0in 0in 0pt;"&gt;&lt;SPAN style="color: black;"&gt;dateFilter1 = arcpy.GetParameterAsText(0)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0in 0in 0pt;"&gt;&lt;SPAN style="color: black;"&gt;dateFilter2 = arcpy.GetParameterAsText(1)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0in 0in 0pt;"&gt;&lt;SPAN style="color: black;"&gt;print dateFilter1&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0in 0in 0pt;"&gt;&lt;SPAN style="color: black;"&gt;print dateFilter2&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0in 0in 0pt;"&gt;&lt;SPAN style="color: black;"&gt;#convert date inputs from string to date format&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0in 0in 0pt;"&gt;&lt;SPAN style="color: black;"&gt;dateDateFilter1 = datetime.strptime (dateFilter1, '%m/%d/%Y')&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0in 0in 0pt;"&gt;&lt;SPAN style="color: black;"&gt;dateDateFilter2 = datetime.strptime (dateFilter2, '%m/%d/%Y')&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0in 0in 0pt;"&gt;&lt;SPAN style="color: black;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0in 0in 0pt;"&gt;&lt;SPAN style="color: black;"&gt;When I look at the attribute table, the date shows up in the format "30/09/2016" for Sept 30, 2016, for example, which does not match what I have in the code above. However, if I run the script tool and select dates say between Oct 2, 2016 and Oct 5, 2016 ("02/10/2016" and "05/10/2016" in the attribute table), I get the records I expect. However, if I select dates between Sept. 29, 2016 and Oct 5, 2016 ("29/09/2016" and 05/10/2016") I get the following error:&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0in 0in 0pt;"&gt;&lt;SPAN style="color: black;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0in 0in 0pt;"&gt;&lt;SPAN style="color: black;"&gt;&amp;nbsp; File "C:\Python27\ArcGIS10.2\Lib\_strptime.py", line 325, in _strptime&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0in 0in 0pt;"&gt;&lt;SPAN style="color: black;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (data_string, format))&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0in 0in 0pt;"&gt;&lt;SPAN style="color: black;"&gt;ValueError: time data '29/09/2016' does not match format '%m/%d/%Y'&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0in 0in 0pt;"&gt;&lt;SPAN style="color: black;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0in 0in 0pt;"&gt;&lt;SPAN style="color: black;"&gt;This seems to suggest that the data in the date field is being read as if it was in "%d/%m/%Y" format. If I change the code so that the format for the strptime command shows "%d/%m/%Y" the script runs without error, but returns no records, which also suggests that it is reading the date in the source data as "%d/%m/%Y" (all records are in late September and early October).&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0in 0in 0pt;"&gt;&lt;SPAN style="color: black;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0in 0in 0pt;"&gt;&lt;SPAN style="color: black;"&gt;Can anyone tell me what might be wrong? &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Oct 2016 17:19:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/how-do-i-ensure-accurate-date-selection-within/m-p/626948#M4217</guid>
      <dc:creator>KarlKeough</dc:creator>
      <dc:date>2016-10-26T17:19:08Z</dc:date>
    </item>
    <item>
      <title>Re: How do I ensure accurate date selection within script tool?</title>
      <link>https://community.esri.com/t5/developers-questions/how-do-i-ensure-accurate-date-selection-within/m-p/626949#M4218</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just curious, if you sort the date field in the attribute table, does it sort how you would expect, or like Oct. 2, Nov. 2., Oct. 3, Nov. 3, etc.?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Oct 2016 18:10:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/how-do-i-ensure-accurate-date-selection-within/m-p/626949#M4218</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2016-10-26T18:10:23Z</dc:date>
    </item>
    <item>
      <title>Re: How do I ensure accurate date selection within script tool?</title>
      <link>https://community.esri.com/t5/developers-questions/how-do-i-ensure-accurate-date-selection-within/m-p/626950#M4219</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It sorts as I would expect, by month and day.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Oct 2016 18:13:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/how-do-i-ensure-accurate-date-selection-within/m-p/626950#M4219</guid>
      <dc:creator>KarlKeough</dc:creator>
      <dc:date>2016-10-26T18:13:22Z</dc:date>
    </item>
    <item>
      <title>Re: How do I ensure accurate date selection within script tool?</title>
      <link>https://community.esri.com/t5/developers-questions/how-do-i-ensure-accurate-date-selection-within/m-p/626951#M4220</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;have you checked the query requirements, your regional settings and your data formats, to see if they match? &amp;nbsp;see the date time section here&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="http://desktop.arcgis.com/en/arcmap/latest/map/working-with-layers/sql-reference-for-query-expressions-used-in-arcgis.htm#GUID-85C03D85-F4A5-48FC-8E8C-3F79919430DB" title="http://desktop.arcgis.com/en/arcmap/latest/map/working-with-layers/sql-reference-for-query-expressions-used-in-arcgis.htm#GUID-85C03D85-F4A5-48FC-8E8C-3F79919430DB"&gt;SQL reference for query expressions used in ArcGIS—Help | ArcGIS for Desktop&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Oct 2016 18:21:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/how-do-i-ensure-accurate-date-selection-within/m-p/626951#M4220</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-10-26T18:21:31Z</dc:date>
    </item>
  </channel>
</rss>

