<?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 you search a date field in a file GDB feature class? in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-do-you-search-a-date-field-in-a-file-gdb/m-p/427461#M11541</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks so much for responding!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;...But when I try &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim DateFrom As String&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;DateFrom = datDateFrom.Text&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim DateTo As String&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;DateTo = datDateTo.Text&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;with the query filter set to:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;pQueryFilter.WhereClause = "OccurredDate1 &amp;gt;= DateFrom And OccurredDate1 &amp;lt;= DateTo"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;nothing gets selected.&amp;nbsp; Yet the selection works fine when I type dates directly into the code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;pQueryFilter.WhereClause = "OccurredDate1 &amp;gt;= date '2009/09/11'&amp;nbsp; And OccurredDate1 &amp;lt;= date '2009/09/11'"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope you can see why I am confused...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 30 Aug 2010 22:07:58 GMT</pubDate>
    <dc:creator>PatriciaPendleton</dc:creator>
    <dc:date>2010-08-30T22:07:58Z</dc:date>
    <item>
      <title>How do you search a date field in a file GDB feature class?</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-do-you-search-a-date-field-in-a-file-gdb/m-p/427459#M11539</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi all,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying to set up an input box so users can select points by a date field.&amp;nbsp; The user types in a "Date From" and a "Date To", and the selection is supposed to occur.&amp;nbsp; However, as the code is, no selection occurs when the input boxes are used.&amp;nbsp; If I were to do the selection manually with the Select by Attribute tool, the dates show up in the format of " date 'YYYY/MM/DD' ", and if I type dates in that format directly into the code, it makes the correct selections--but I get a type mismatch error if that's typed into the user boxes.&amp;nbsp; Where am I going wrong?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Ideally, I'd like the user to be able to type the date in the format of just MM/DD/YYYY, as that is how the dates are displayed in the attribute table, but whatever will work will do.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance for any help!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;Public Sub GetDates()

Dim pDoc As IMxDocument
Dim pMap As IMap
Dim pActiveView As IActiveView
Dim pFeatureLayer As IFeatureLayer
Set pDoc = ThisDocument
Set pMap = pDoc.FocusMap
Set pActiveView = pMap

Dim pQueryFilter As IQueryFilter
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pFeatureSelection As IFeatureSelection

Dim DateFrom As Date
DateFrom = datDateFrom.Text
Dim DateTo As Date
DateTo = datDateTo.Text

'Other alternatives I can think of also don't work, such as:
'Dim DateFrom As String '(or Date)
'DateFrom = "date '" &amp;amp; datDateFrom.Text &amp;amp; "''
'Dim DateTo As String '(or Date)
'DateTo = "date '" &amp;amp; datDateTo.Text &amp;amp;"'"&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 

&amp;nbsp;&amp;nbsp;&amp;nbsp; Application.Document.CommandBars.Find(ArcID.Query_ClearSelection).Execute
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pFeatureLayer = pMap.Layer(0)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 'Prepare a query filter
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pQueryFilter = New QueryFilter
&amp;nbsp;&amp;nbsp;&amp;nbsp; pQueryFilter.WhereClause = "OccurredDate1 &amp;gt;= DateFrom And OccurredDate1 &amp;lt;= DateTo"
&amp;nbsp;&amp;nbsp;&amp;nbsp; 'Refresh the old selection, if any, and erase it
&amp;nbsp;&amp;nbsp;&amp;nbsp; pActiveView.PartialRefresh esriViewGeoSelection, Nothing, Nothing
&amp;nbsp;&amp;nbsp;&amp;nbsp; 'Select features
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pFeatureSelection = pFeatureLayer
&amp;nbsp;&amp;nbsp;&amp;nbsp; pFeatureSelection.SelectFeatures pQueryFilter, esriSelectionResultNew, False
&amp;nbsp;&amp;nbsp;&amp;nbsp; 'Refresh again to draw the new selection
&amp;nbsp;&amp;nbsp;&amp;nbsp; pActiveView.PartialRefresh esriViewGeoSelection, Nothing, Nothing
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
End Sub&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Patricia Pendleton&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Center for Geographical Studies&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Cal State University, Northridge&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Aug 2010 19:44:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-do-you-search-a-date-field-in-a-file-gdb/m-p/427459#M11539</guid>
      <dc:creator>PatriciaPendleton</dc:creator>
      <dc:date>2010-08-30T19:44:02Z</dc:date>
    </item>
    <item>
      <title>Re: How do you search a date field in a file GDB feature class?</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-do-you-search-a-date-field-in-a-file-gdb/m-p/427460#M11540</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Define DateFrom and DateTo as string rather than date.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Lance&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hi all,&lt;BR /&gt;I am trying to set up an input box so users can select points by a date field.&amp;nbsp; The user types in a "Date From" and a "Date To", and the selection is supposed to occur.&amp;nbsp; However, as the code is, no selection occurs when the input boxes are used.&amp;nbsp; If I were to do the selection manually with the Select by Attribute tool, the dates show up in the format of " date 'YYYY/MM/DD' ", and if I type dates in that format directly into the code, it makes the correct selections--but I get a type mismatch error if that's typed into the user boxes.&amp;nbsp; Where am I going wrong?&lt;BR /&gt;&lt;BR /&gt;Ideally, I'd like the user to be able to type the date in the format of just MM/DD/YYYY, as that is how the dates are displayed in the attribute table, but whatever will work will do.&lt;BR /&gt;&lt;BR /&gt;Thanks in advance for any help!&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Public Sub GetDates()

Dim pDoc As IMxDocument
Dim pMap As IMap
Dim pActiveView As IActiveView
Dim pFeatureLayer As IFeatureLayer
Set pDoc = ThisDocument
Set pMap = pDoc.FocusMap
Set pActiveView = pMap

Dim pQueryFilter As IQueryFilter
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pFeatureSelection As IFeatureSelection

Dim DateFrom As Date
DateFrom = datDateFrom.Text
Dim DateTo As Date
DateTo = datDateTo.Text

'Other alternatives I can think of also don't work, such as:
'Dim DateFrom As String '(or Date)
'DateFrom = "date '" &amp;amp; datDateFrom.Text &amp;amp; "''
'Dim DateTo As String '(or Date)
'DateTo = "date '" &amp;amp; datDateTo.Text &amp;amp;"'"&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 

&amp;nbsp;&amp;nbsp;&amp;nbsp; Application.Document.CommandBars.Find(ArcID.Query_ClearSelection).Execute
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pFeatureLayer = pMap.Layer(0)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 'Prepare a query filter
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pQueryFilter = New QueryFilter
&amp;nbsp;&amp;nbsp;&amp;nbsp; pQueryFilter.WhereClause = "OccurredDate1 &amp;gt;= DateFrom And OccurredDate1 &amp;lt;= DateTo"
&amp;nbsp;&amp;nbsp;&amp;nbsp; 'Refresh the old selection, if any, and erase it
&amp;nbsp;&amp;nbsp;&amp;nbsp; pActiveView.PartialRefresh esriViewGeoSelection, Nothing, Nothing
&amp;nbsp;&amp;nbsp;&amp;nbsp; 'Select features
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set pFeatureSelection = pFeatureLayer
&amp;nbsp;&amp;nbsp;&amp;nbsp; pFeatureSelection.SelectFeatures pQueryFilter, esriSelectionResultNew, False
&amp;nbsp;&amp;nbsp;&amp;nbsp; 'Refresh again to draw the new selection
&amp;nbsp;&amp;nbsp;&amp;nbsp; pActiveView.PartialRefresh esriViewGeoSelection, Nothing, Nothing
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
End Sub&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;Patricia Pendleton&lt;BR /&gt;Center for Geographical Studies&lt;BR /&gt;Cal State University, Northridge&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:14:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-do-you-search-a-date-field-in-a-file-gdb/m-p/427460#M11540</guid>
      <dc:creator>LanceShipman</dc:creator>
      <dc:date>2021-12-11T19:14:26Z</dc:date>
    </item>
    <item>
      <title>Re: How do you search a date field in a file GDB feature class?</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-do-you-search-a-date-field-in-a-file-gdb/m-p/427461#M11541</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks so much for responding!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;...But when I try &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim DateFrom As String&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;DateFrom = datDateFrom.Text&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim DateTo As String&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;DateTo = datDateTo.Text&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;with the query filter set to:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;pQueryFilter.WhereClause = "OccurredDate1 &amp;gt;= DateFrom And OccurredDate1 &amp;lt;= DateTo"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;nothing gets selected.&amp;nbsp; Yet the selection works fine when I type dates directly into the code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;pQueryFilter.WhereClause = "OccurredDate1 &amp;gt;= date '2009/09/11'&amp;nbsp; And OccurredDate1 &amp;lt;= date '2009/09/11'"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope you can see why I am confused...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Aug 2010 22:07:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-do-you-search-a-date-field-in-a-file-gdb/m-p/427461#M11541</guid>
      <dc:creator>PatriciaPendleton</dc:creator>
      <dc:date>2010-08-30T22:07:58Z</dc:date>
    </item>
    <item>
      <title>Re: How do you search a date field in a file GDB feature class?</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-do-you-search-a-date-field-in-a-file-gdb/m-p/427462#M11542</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;pQueryFilter.WhereClause = "OccurredDate1 &amp;gt;= DateFrom And OccurredDate1 &amp;lt;= DateTo"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Should be:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;pQueryFilter.WhereClause = "OccurredDate1 &amp;gt;= " &amp;amp; DateFrom &amp;amp; " And OccurredDate1 &amp;lt;= " &amp;amp; DateTo&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The variables will not be in the string otherwise. For debugging reasons you may want to print out the where clause string.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Debug.Print pQueryFilter.WhereClause&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Aug 2010 22:13:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-do-you-search-a-date-field-in-a-file-gdb/m-p/427462#M11542</guid>
      <dc:creator>LanceShipman</dc:creator>
      <dc:date>2010-08-30T22:13:06Z</dc:date>
    </item>
    <item>
      <title>Re: How do you search a date field in a file GDB feature class?</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-do-you-search-a-date-field-in-a-file-gdb/m-p/427463#M11543</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Patricia:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Your problem is with the line of code below:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; pQueryFilter.WhereClause = "OccurredDate1 &amp;gt;= DateFrom And OccurredDate1 &amp;lt;= DateTo"
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This would be translated as though DateFrom and DateTo are actual fields in your feature class (like OccurredDate1) rather than as date values that the user is supplying.&amp;nbsp; In case Lance's suggested syntax does not work try the clause below to replicate the format you said worked:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;pQueryFilter.WhereClause = "OccurredDate1 &amp;gt;= date '" &amp;amp; format(DateFrom, "YYYY/MM/DD") &amp;amp; "' And OccurredDate1 &amp;lt;= date '" &amp;amp;&amp;nbsp; format(DateTo, "YYYY/MM/DD") &amp;amp; "'"&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:14:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-do-you-search-a-date-field-in-a-file-gdb/m-p/427463#M11543</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2021-12-11T19:14:28Z</dc:date>
    </item>
    <item>
      <title>Re: How do you search a date field in a file GDB feature class?</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-do-you-search-a-date-field-in-a-file-gdb/m-p/427464#M11544</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;"Ah, I see!" said the blind newbie.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks so much for the explanation, worked like a charm.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Aug 2010 22:39:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-do-you-search-a-date-field-in-a-file-gdb/m-p/427464#M11544</guid>
      <dc:creator>PatriciaPendleton</dc:creator>
      <dc:date>2010-08-30T22:39:08Z</dc:date>
    </item>
  </channel>
</rss>

