<?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: Select by Attribute SQL Expression using Dates: in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/select-by-attribute-sql-expression-using-dates/m-p/4023#M181</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hello,&lt;BR /&gt;I have a table with Expiration Dates.&amp;nbsp; I want to use the select by attributes to tell me what dates are between now and exactly one year.&amp;nbsp; Thanks in advance for any help.&lt;BR /&gt;Mark&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am going to assume you are using a File geodatabase, since I am most familiar with that database and you did not say what database you actually are using.&amp;nbsp; All SQL help is dependent on the database you are working with, so until you provide that information you really can't get help that deals with your specific needs.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This expression will select all records based on the current date and within the last year when time of day is not a factor (accounting for leap year):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;(EXTRACT(MONTH FROM CURRENT_DATE) = EXTRACT(MONTH FROM CURRENT_DATE - 365) AND EXTRACT(DAY FROM CURRENT_DATE) = EXTRACT(DAY FROM CURRENT_DATE - 365) AND "CREATED" &amp;lt;= CURRENT_DATE AND "CREATED" &amp;gt; CURRENT_DATE - 365) OR (EXTRACT(MONTH FROM CURRENT_DATE) = EXTRACT(MONTH FROM CURRENT_DATE - 366) AND EXTRACT(DAY FROM CURRENT_DATE) = EXTRACT(DAY FROM CURRENT_DATE - 366) AND "CREATED" &amp;lt;= CURRENT_DATE AND "CREATED" &amp;gt; CURRENT_DATE - 366) OR (EXTRACT(MONTH FROM CURRENT_DATE) = 2 AND EXTRACT(DAY FROM CURRENT_DATE) = 29 AND "CREATED" &amp;lt;= CURRENT_DATE AND "CREATED" &amp;gt; CURRENT_DATE - 366)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This expression will select all records based on the current date and time stamp to immediately after the exact same time on the same date 1 year ago (accounting for leap year):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;(EXTRACT(MONTH FROM CURRENT_TIMESTAMP) = EXTRACT(MONTH FROM CURRENT_TIMESTAMP - 365) AND EXTRACT(DAY FROM CURRENT_TIMESTAMP) = EXTRACT(DAY FROM CURRENT_TIMESTAMP - 365) AND "CREATED" &amp;lt;= CURRENT_TIMESTAMP AND "CREATED" &amp;gt; CURRENT_TIMESTAMP - 365) OR (EXTRACT(MONTH FROM CURRENT_TIMESTAMP) = EXTRACT(MONTH FROM CURRENT_TIMESTAMP - 366) AND EXTRACT(DAY FROM CURRENT_TIMESTAMP) = EXTRACT(DAY FROM CURRENT_TIMESTAMP - 366) AND "CREATED" &amp;lt;= CURRENT_TIMESTAMP AND "CREATED" &amp;gt; CURRENT_TIMESTAMP - 366) OR (EXTRACT(MONTH FROM CURRENT_TIMESTAMP) = 2 AND EXTRACT(DAY FROM CURRENT_TIMESTAMP) = 29 AND "CREATED" &amp;lt;= CURRENT_TIMESTAMP AND "CREATED" &amp;gt; CURRENT_TIMESTAMP - 366)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am using matching date logic for leap years rather than end of the month logic so that 2/28/2013 looks back to 2/28/2012.&amp;nbsp; I have not worked out how to get end of the month logic to work so that you go from 2/28/2013 back to 2/29/2012.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Speaking to the programmer for the file geodatabase at the ESRI UC this year I found out that file geodatabase SQL complies with all by a few SQL 92 specifications, so you can look up help on the internet for the SQL 92 syntax and normally apply it to the file geodatabase.&amp;nbsp; That is how I found out that CURRENT_TIMESTAMP works with a file geodatabase.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 17 Jul 2013 16:04:30 GMT</pubDate>
    <dc:creator>RichardFairhurst</dc:creator>
    <dc:date>2013-07-17T16:04:30Z</dc:date>
    <item>
      <title>Select by Attribute SQL Expression using Dates:</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/select-by-attribute-sql-expression-using-dates/m-p/4021#M179</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a table with Expiration Dates.&amp;nbsp; I want to use the select by attributes to tell me what dates are between now and exactly one year.&amp;nbsp; Thanks in advance for any help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mark&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jul 2013 12:49:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/select-by-attribute-sql-expression-using-dates/m-p/4021#M179</guid>
      <dc:creator>MarkEnglish</dc:creator>
      <dc:date>2013-07-17T12:49:15Z</dc:date>
    </item>
    <item>
      <title>Re: Select by Attribute SQL Expression using Dates:</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/select-by-attribute-sql-expression-using-dates/m-p/4022#M180</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This has worked for me.&amp;nbsp; It creates a a new table by selecting from one table INTO another.&amp;nbsp; It's the between statement you want.&amp;nbsp; Your mileage may vary and sorry, no tech support is available...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;SELECT&amp;nbsp;&amp;nbsp;&amp;nbsp; Field1, Field2 Field3, Field_ETC_ETC&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;INTO&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; db.dbowner.tablename2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;FROM&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; db.dbowner.tablename1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;WHERE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (YourDateField &lt;/SPAN&gt;&lt;STRONG&gt;BETWEEN '2013/03/19 00:00' AND '2013/06/10 00:00'&lt;/STRONG&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ORDER BY YourDateField&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www.w3schools.com/sql/"&gt;Here is a great site for learning sql expressions&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jul 2013 14:10:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/select-by-attribute-sql-expression-using-dates/m-p/4022#M180</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2013-07-17T14:10:32Z</dc:date>
    </item>
    <item>
      <title>Re: Select by Attribute SQL Expression using Dates:</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/select-by-attribute-sql-expression-using-dates/m-p/4023#M181</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hello,&lt;BR /&gt;I have a table with Expiration Dates.&amp;nbsp; I want to use the select by attributes to tell me what dates are between now and exactly one year.&amp;nbsp; Thanks in advance for any help.&lt;BR /&gt;Mark&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am going to assume you are using a File geodatabase, since I am most familiar with that database and you did not say what database you actually are using.&amp;nbsp; All SQL help is dependent on the database you are working with, so until you provide that information you really can't get help that deals with your specific needs.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This expression will select all records based on the current date and within the last year when time of day is not a factor (accounting for leap year):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;(EXTRACT(MONTH FROM CURRENT_DATE) = EXTRACT(MONTH FROM CURRENT_DATE - 365) AND EXTRACT(DAY FROM CURRENT_DATE) = EXTRACT(DAY FROM CURRENT_DATE - 365) AND "CREATED" &amp;lt;= CURRENT_DATE AND "CREATED" &amp;gt; CURRENT_DATE - 365) OR (EXTRACT(MONTH FROM CURRENT_DATE) = EXTRACT(MONTH FROM CURRENT_DATE - 366) AND EXTRACT(DAY FROM CURRENT_DATE) = EXTRACT(DAY FROM CURRENT_DATE - 366) AND "CREATED" &amp;lt;= CURRENT_DATE AND "CREATED" &amp;gt; CURRENT_DATE - 366) OR (EXTRACT(MONTH FROM CURRENT_DATE) = 2 AND EXTRACT(DAY FROM CURRENT_DATE) = 29 AND "CREATED" &amp;lt;= CURRENT_DATE AND "CREATED" &amp;gt; CURRENT_DATE - 366)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This expression will select all records based on the current date and time stamp to immediately after the exact same time on the same date 1 year ago (accounting for leap year):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;(EXTRACT(MONTH FROM CURRENT_TIMESTAMP) = EXTRACT(MONTH FROM CURRENT_TIMESTAMP - 365) AND EXTRACT(DAY FROM CURRENT_TIMESTAMP) = EXTRACT(DAY FROM CURRENT_TIMESTAMP - 365) AND "CREATED" &amp;lt;= CURRENT_TIMESTAMP AND "CREATED" &amp;gt; CURRENT_TIMESTAMP - 365) OR (EXTRACT(MONTH FROM CURRENT_TIMESTAMP) = EXTRACT(MONTH FROM CURRENT_TIMESTAMP - 366) AND EXTRACT(DAY FROM CURRENT_TIMESTAMP) = EXTRACT(DAY FROM CURRENT_TIMESTAMP - 366) AND "CREATED" &amp;lt;= CURRENT_TIMESTAMP AND "CREATED" &amp;gt; CURRENT_TIMESTAMP - 366) OR (EXTRACT(MONTH FROM CURRENT_TIMESTAMP) = 2 AND EXTRACT(DAY FROM CURRENT_TIMESTAMP) = 29 AND "CREATED" &amp;lt;= CURRENT_TIMESTAMP AND "CREATED" &amp;gt; CURRENT_TIMESTAMP - 366)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am using matching date logic for leap years rather than end of the month logic so that 2/28/2013 looks back to 2/28/2012.&amp;nbsp; I have not worked out how to get end of the month logic to work so that you go from 2/28/2013 back to 2/29/2012.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Speaking to the programmer for the file geodatabase at the ESRI UC this year I found out that file geodatabase SQL complies with all by a few SQL 92 specifications, so you can look up help on the internet for the SQL 92 syntax and normally apply it to the file geodatabase.&amp;nbsp; That is how I found out that CURRENT_TIMESTAMP works with a file geodatabase.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Jul 2013 16:04:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/select-by-attribute-sql-expression-using-dates/m-p/4023#M181</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2013-07-17T16:04:30Z</dc:date>
    </item>
  </channel>
</rss>

