<?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 search for Today's date minus 5 with arcpy.da.searchcursor in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-search-for-today-s-date-minus-5-with-arcpy/m-p/1552803#M73099</link>
    <description>&lt;P&gt;For FGDB, this is also working for me:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;qry = """DateField &amp;gt;= (current_date- 5)"""
with  arcpy.da.SearchCursor(updateFC, ['DateField'],qry) as cursor:
     Do stuff on data from last 5 days.&lt;/LI-CODE&gt;&lt;P&gt;R_&lt;/P&gt;</description>
    <pubDate>Mon, 28 Oct 2024 14:59:09 GMT</pubDate>
    <dc:creator>RhettZufelt</dc:creator>
    <dc:date>2024-10-28T14:59:09Z</dc:date>
    <item>
      <title>How to search for Today's date minus 5 with arcpy.da.searchcursor</title>
      <link>https://community.esri.com/t5/python-questions/how-to-search-for-today-s-date-minus-5-with-arcpy/m-p/1551493#M73080</link>
      <description>&lt;P&gt;Good afternoon,&lt;/P&gt;&lt;P&gt;I am looking for a way to enter in the where condition in&amp;nbsp; an arcpy.da.searchcursor&amp;nbsp; a date.&lt;/P&gt;&lt;P&gt;How can I search for all the records that where created in the last 5 days.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Oct 2024 18:31:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-search-for-today-s-date-minus-5-with-arcpy/m-p/1551493#M73080</guid>
      <dc:creator>JoseSanchez</dc:creator>
      <dc:date>2024-10-23T18:31:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to search for Today's date minus 5 with arcpy.da.searchcursor</title>
      <link>https://community.esri.com/t5/python-questions/how-to-search-for-today-s-date-minus-5-with-arcpy/m-p/1551568#M73083</link>
      <description>&lt;P&gt;Something like this code will help you find the date you want to limit your search from, then from there you can use the value returned from that function in a query within your search cursor 'where clause' to filter the data. The second bit of code shows one way you could do that. You'll want to read up on the datetime module and&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def calc_date(daysbefore):
    day = datetime.date.today() #gets todays date
    longago = datetime.timedelta(days = daysbefore) #creates a datetime object for calculations
    datebefore = day-longago #subtracts the number of days desired from today
    return datebefore.strftime("%m/%d/%Y")#returns a text string in the form of dd/mm/yyyy)&lt;/LI-CODE&gt;&lt;P&gt;this code is going to be buggy because this is just an example of how i think this would come together for you.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#indata is the datasource you are searching
#fieldlist is the list of fields you want returned with your query, ['*'] will return all but if there are alot you should be more specific
start = calc_date(5) #uses function above to create a start date for your query
qry = f"datefield &amp;gt;= '{start}'" #the sql query you'll use in the SearchCursor
with arcpy.da.SearchCursor(indata,fieldlist,sql_clause = qry)as cursor
  &amp;lt;code you run after&amp;gt; &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Oct 2024 19:33:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-search-for-today-s-date-minus-5-with-arcpy/m-p/1551568#M73083</guid>
      <dc:creator>clt_cabq</dc:creator>
      <dc:date>2024-10-23T19:33:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to search for Today's date minus 5 with arcpy.da.searchcursor</title>
      <link>https://community.esri.com/t5/python-questions/how-to-search-for-today-s-date-minus-5-with-arcpy/m-p/1551591#M73084</link>
      <description>&lt;P&gt;SQL date functions tend to vary across data source, so there will be no single SQL that will be widely portable.&amp;nbsp; See &lt;A href="https://pro.arcgis.com/en/pro-app/latest/help/mapping/navigation/sql-reference-for-elements-used-in-query-expressions.htm" target="_blank"&gt;SQL reference for query expressions used in ArcGIS—ArcGIS Pro | Documentation&lt;/A&gt; for more information and examples.&amp;nbsp; A purely Python cursor-based will be much more portable.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Oct 2024 20:04:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-search-for-today-s-date-minus-5-with-arcpy/m-p/1551591#M73084</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2024-10-23T20:04:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to search for Today's date minus 5 with arcpy.da.searchcursor</title>
      <link>https://community.esri.com/t5/python-questions/how-to-search-for-today-s-date-minus-5-with-arcpy/m-p/1551601#M73085</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1371"&gt;@JoshuaBixby&lt;/a&gt;&amp;nbsp;thanks for interjecting that.. oracle and MS sql server can have very different looking queries, so the details could be pretty different.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Oct 2024 20:11:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-search-for-today-s-date-minus-5-with-arcpy/m-p/1551601#M73085</guid>
      <dc:creator>clt_cabq</dc:creator>
      <dc:date>2024-10-23T20:11:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to search for Today's date minus 5 with arcpy.da.searchcursor</title>
      <link>https://community.esri.com/t5/python-questions/how-to-search-for-today-s-date-minus-5-with-arcpy/m-p/1552143#M73088</link>
      <description>&lt;P&gt;this is working for me with SQL server data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;qry = """DateField &amp;gt;= (GetDate() - 5)"""
with  arcpy.da.SearchCursor(updateFC, ['DateField'],qry) as cursor:
     Do stuff on data from last 5 days.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2024 22:51:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-search-for-today-s-date-minus-5-with-arcpy/m-p/1552143#M73088</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2024-10-24T22:51:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to search for Today's date minus 5 with arcpy.da.searchcursor</title>
      <link>https://community.esri.com/t5/python-questions/how-to-search-for-today-s-date-minus-5-with-arcpy/m-p/1552719#M73096</link>
      <description>&lt;P&gt;Good morning,&lt;/P&gt;&lt;P&gt;Thank you everyone for your answers.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am going to query a FGDB.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;from datetime import datetime, timedelta

date_past = datetime.now() - timedelta(days=180)

wc = "DateField &amp;lt; DATE '{}'".format(date_past.strftime("%Y-%m-%d %H:%M:%S"))

print wc‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;/PRE&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/python-questions/use-date-timestamp-field-to-select-features/td-p/295481" target="_blank" rel="noopener"&gt;Solved: Use date timestamp field to select features - Esri Community&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2024 11:38:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-search-for-today-s-date-minus-5-with-arcpy/m-p/1552719#M73096</guid>
      <dc:creator>JoseSanchez</dc:creator>
      <dc:date>2024-10-28T11:38:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to search for Today's date minus 5 with arcpy.da.searchcursor</title>
      <link>https://community.esri.com/t5/python-questions/how-to-search-for-today-s-date-minus-5-with-arcpy/m-p/1552803#M73099</link>
      <description>&lt;P&gt;For FGDB, this is also working for me:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;qry = """DateField &amp;gt;= (current_date- 5)"""
with  arcpy.da.SearchCursor(updateFC, ['DateField'],qry) as cursor:
     Do stuff on data from last 5 days.&lt;/LI-CODE&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2024 14:59:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-search-for-today-s-date-minus-5-with-arcpy/m-p/1552803#M73099</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2024-10-28T14:59:09Z</dc:date>
    </item>
  </channel>
</rss>

