<?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 Select Analysis Whereclause is like date string variable in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/select-analysis-whereclause-is-like-date-string/m-p/603618#M47161</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;dayString is a string that will change frequently.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to use python to select records where my field EXP_CST (date field) in my feature class is on the same day as the date string. However, the date field will also have time elements, so I believe I will need to use the LIKE operator? I am using ArcGIS 10.5.1. Thank you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;dayString = '2018-01-31'&lt;/P&gt;&lt;P&gt;arcpy.Select_analysis(Select2, Select3, "EXP_CST LIKE '" + dayString + "'")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/395748_pastedImage_1.png" style="width: auto; height: auto;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 05 Feb 2018 15:28:57 GMT</pubDate>
    <dc:creator>AndrewL</dc:creator>
    <dc:date>2018-02-05T15:28:57Z</dc:date>
    <item>
      <title>Select Analysis Whereclause is like date string variable</title>
      <link>https://community.esri.com/t5/python-questions/select-analysis-whereclause-is-like-date-string/m-p/603618#M47161</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;dayString is a string that will change frequently.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to use python to select records where my field EXP_CST (date field) in my feature class is on the same day as the date string. However, the date field will also have time elements, so I believe I will need to use the LIKE operator? I am using ArcGIS 10.5.1. Thank you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;dayString = '2018-01-31'&lt;/P&gt;&lt;P&gt;arcpy.Select_analysis(Select2, Select3, "EXP_CST LIKE '" + dayString + "'")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/395748_pastedImage_1.png" style="width: auto; height: auto;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Feb 2018 15:28:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-analysis-whereclause-is-like-date-string/m-p/603618#M47161</guid>
      <dc:creator>AndrewL</dc:creator>
      <dc:date>2018-02-05T15:28:57Z</dc:date>
    </item>
    <item>
      <title>Re: Select Analysis Whereclause is like date string variable</title>
      <link>https://community.esri.com/t5/python-questions/select-analysis-whereclause-is-like-date-string/m-p/603619#M47162</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Andrew,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dates are handled differently depending on what database you are using?&amp;nbsp; Are you querying a shapefile, file geodatabase, personal geodatabase, sql server, postgis, oracle ....&amp;nbsp; &amp;nbsp;all these have different formats to address when dealing with date data.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please give the database type from which you want to apply the where clasue to, this will help folks properly answer you questions.&amp;nbsp; Each of the different databases has there own unique way of handling "Time" -- Generally speaking, using format statements are a way of striping off the time portion, also converting to Month, day and year to make your comparisons is another.&amp;nbsp; At first glance, it seems that you could search for your date directly... it is not appearent from your question if you are working with true dates (you mentioned that EXP_CST is a date field then in your are comparing a string with a date -- this will not work with all databases to it is important to mention what database you are working with.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Look here under dates and time to see how to covert string dates to dates ....for the various types databases.&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="http://pro.arcgis.com/en/pro-app/help/mapping/navigation/sql-reference-for-elements-used-in-query-expressions.htm" title="http://pro.arcgis.com/en/pro-app/help/mapping/navigation/sql-reference-for-elements-used-in-query-expressions.htm"&gt;SQL reference for query expressions used in ArcGIS—ArcGIS Pro | ArcGIS Desktop&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Feb 2018 15:57:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-analysis-whereclause-is-like-date-string/m-p/603619#M47162</guid>
      <dc:creator>TedKowal</dc:creator>
      <dc:date>2018-02-05T15:57:56Z</dc:date>
    </item>
    <item>
      <title>Re: Select Analysis Whereclause is like date string variable</title>
      <link>https://community.esri.com/t5/python-questions/select-analysis-whereclause-is-like-date-string/m-p/603620#M47163</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you I am using a file geodatabase.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Feb 2018 16:01:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-analysis-whereclause-is-like-date-string/m-p/603620#M47163</guid>
      <dc:creator>AndrewL</dc:creator>
      <dc:date>2018-02-05T16:01:45Z</dc:date>
    </item>
    <item>
      <title>Re: Select Analysis Whereclause is like date string variable</title>
      <link>https://community.esri.com/t5/python-questions/select-analysis-whereclause-is-like-date-string/m-p/603621#M47164</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This may help:&lt;/P&gt;&lt;P&gt;import arcpy as ap&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;table = &amp;lt;path_to_table&amp;gt;&lt;BR /&gt;dest_table = &amp;lt;path_for_your_output&amp;gt;&lt;BR /&gt;field_name ='EXP_CST'&lt;BR /&gt;day_string = '2018-01-31'&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# If your string sequence is marked by double quotes, single quotes can be simply used&amp;nbsp; inside the string. &lt;BR /&gt;# The two '%' represents any number of signs (including none) before and after the string you're looking for.&lt;BR /&gt;# Use ap.AddFieldDelimiters to be flexible in shp, mdb, fgdb and others dataformats.&lt;BR /&gt;sql_expression = "{field} LIKE '%{sub_string}%'".format(field=ap.AddFieldDelimiters(table, &lt;BR /&gt;&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;&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;&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;&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;&amp;nbsp; field_name), &lt;BR /&gt;&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;&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;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sub_string=day_string)&lt;BR /&gt;sql_expression #prompt the result&lt;BR /&gt;ap.analysis.Select(table, dest_table, sql_expression)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This code doesn't include a solution for transforming string to date and maybe reverse.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Feb 2018 16:48:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-analysis-whereclause-is-like-date-string/m-p/603621#M47164</guid>
      <dc:creator>LotharUlferts</dc:creator>
      <dc:date>2018-02-05T16:48:19Z</dc:date>
    </item>
    <item>
      <title>Re: Select Analysis Whereclause is like date string variable</title>
      <link>https://community.esri.com/t5/python-questions/select-analysis-whereclause-is-like-date-string/m-p/603622#M47165</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;From the link you sent I used the&amp;nbsp;&lt;SPAN style="color: #4c4c4c; background-color: #ffffff; font-weight: 300;"&gt;EXTRACT&lt;/SPAN&gt;&lt;EM style="color: #4c4c4c; background-color: #ffffff; font-weight: 300;"&gt;(extract_field&amp;nbsp;&lt;/EM&gt;&lt;SPAN style="color: #4c4c4c; background-color: #ffffff; font-weight: 300;"&gt;FROM&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;EM style="color: #4c4c4c; background-color: #ffffff; font-weight: 300;"&gt;extract_source).&lt;/EM&gt; I am not sure the LIKE operator is functional with a date field. I kept getting errors.&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, using EXTRACT seems to work. My variables are strings.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #4c4c4c; background-color: #ffffff; font-weight: 300;"&gt;arcpy.Select_analysis(&lt;SPAN style="color: #3d3d3d; font-weight: 400;"&gt;Select2&lt;/SPAN&gt;, &lt;SPAN style="color: #3d3d3d; font-weight: 400;"&gt;Select3&lt;/SPAN&gt;, "EXTRACT(DAY FROM EXP_CST) = "+dayDay+" AND EXTRACT(MONTH FROM EXP_CST) = "+dayMonth+" AND EXTRACT(YEAR FROM EXP_CST) = "+dayYear+"")&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Feb 2018 19:23:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-analysis-whereclause-is-like-date-string/m-p/603622#M47165</guid>
      <dc:creator>AndrewL</dc:creator>
      <dc:date>2018-02-05T19:23:57Z</dc:date>
    </item>
    <item>
      <title>Re: Select Analysis Whereclause is like date string variable</title>
      <link>https://community.esri.com/t5/python-questions/select-analysis-whereclause-is-like-date-string/m-p/603623#M47166</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes that works, however as a tip.... I would also test and deal with "NULL" values for the EXP_CST string.&amp;nbsp; Null values seem to ocasionally pop up and bite you when you least expect them.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;NOT "EXP_CST" IS NULL and EXTRACT(...)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;Your Extract, I believe might fail with a null value.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;Good Work!&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Feb 2018 15:41:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-analysis-whereclause-is-like-date-string/m-p/603623#M47166</guid>
      <dc:creator>TedKowal</dc:creator>
      <dc:date>2018-02-06T15:41:09Z</dc:date>
    </item>
    <item>
      <title>Re: Select Analysis Whereclause is like date string variable</title>
      <link>https://community.esri.com/t5/python-questions/select-analysis-whereclause-is-like-date-string/m-p/603624#M47167</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Nice tip on using AddFieldDelimiters...... have to remember that!&amp;nbsp; Generally I have always used brute force in shaping the data prior to the SQL call.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Feb 2018 16:10:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-analysis-whereclause-is-like-date-string/m-p/603624#M47167</guid>
      <dc:creator>TedKowal</dc:creator>
      <dc:date>2018-02-06T16:10:34Z</dc:date>
    </item>
  </channel>
</rss>

