<?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: Using timedelta  to add days to a start date in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/using-timedelta-to-add-days-to-a-start-date/m-p/1487957#M70767</link>
    <description>&lt;P&gt;Thanks for reply Tom. Yep thats where I started also. Got there in the end. In a roundabout way.&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;Survey_Data = arcpy.GetParameterAsText(0)     
Date_last_treatment = arcpy.GetParameterAsText(1)
AGrowth = arcpy.GetParameterAsText(2)
Initial_date=datetime.datetime.strptime(Date_last_treatment,'%d/%m/%Y')
Growth = int(AGrowth)
if Growth == 10:
    Ndays = 10
elif Growth == 20:
    Ndays = 20
N_date = Intial_date + datetime.timedelta(days = Ndays)
Start_date= datetime.datetime.strftime(N_date, '%d/%m/%Y')
Start_date1 = "timestamp'{}'".format(Start_date)
Where_Clause = "DateTimeUTC &amp;gt;= {}".format(Start_date1)
arcpy.management.SelectLayerByAttribute(Survey_Data, "NEW_SELECTION", Where_Clause)&lt;/LI-CODE&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 12 Jun 2024 02:10:37 GMT</pubDate>
    <dc:creator>JasmineSpring</dc:creator>
    <dc:date>2024-06-12T02:10:37Z</dc:date>
    <item>
      <title>Using timedelta  to add days to a start date</title>
      <link>https://community.esri.com/t5/python-questions/using-timedelta-to-add-days-to-a-start-date/m-p/1486874#M70746</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;I am trying to create a scriptool&amp;nbsp; to select the survey data after a certain start date&lt;/P&gt;&lt;P&gt;If Annual_Growth is 10 I want it to add 20 days to the &amp;nbsp;Initial_Date to give the start date&lt;/P&gt;&lt;P&gt;If Annual_Growth is 20 I want it to add 50 days to the &amp;nbsp;Initial_Date to give the start date&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;&lt;LI-CODE lang="python"&gt;Survey_Data = arcpy.GetParameterAsText(0) 
Annual_Growth = arcpy.GetParameterAsText(1) 
Initial_Date = arcpy.GetParameterAsText(2)  #Date input (date format is dd/mm/yyyy)
T_date = datetime.datetime(Inital_Date)
start_date = T_date + datetime.timedelta(days = num_days)
if Annual_Growth ==10: num_days = 20
elif Annual_Growth == 20: num_days = 50
Where_Clause = "DateTimeUTC &amp;gt;= '{}'".format(start_date)
arcpy.management.SelectLayerByAttribute(Survey_Data, "NEW_SELECTION", Where_Clause)&lt;/LI-CODE&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;&lt;P&gt;The first issue I run into is that the initial date input is perhaps in the wrong format for timedelta to add the days ?? Any help would be appreciated. Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jun 2024 00:13:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-timedelta-to-add-days-to-a-start-date/m-p/1486874#M70746</guid>
      <dc:creator>JasmineSpring</dc:creator>
      <dc:date>2024-06-10T00:13:40Z</dc:date>
    </item>
    <item>
      <title>Re: Using timedelta  to add days to a start date</title>
      <link>https://community.esri.com/t5/python-questions/using-timedelta-to-add-days-to-a-start-date/m-p/1487327#M70755</link>
      <description>&lt;P&gt;A couple things come to mind…&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;When testing, I would add to your script&lt;OL&gt;&lt;LI&gt;print(type(Initial_Date))&lt;OL&gt;&lt;LI&gt;That way you can tell what date type it is and research how to do a time delta to that format (or if you need to convert it to a different datetime format)&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;I have seen issues where a date query doesn’t work unless I give it a range of dates.&lt;OL&gt;&lt;LI&gt;Date &amp;gt; 6/6/2024&lt;OL&gt;&lt;LI&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; In some cases that does not work&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;Date &amp;gt; 6/6/2024 and Date&amp;lt;1/1/2099&lt;OL&gt;&lt;LI&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Works when the first one doesn’t&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;/OL&gt;</description>
      <pubDate>Fri, 07 Jun 2024 16:24:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-timedelta-to-add-days-to-a-start-date/m-p/1487327#M70755</guid>
      <dc:creator>Tom_Laue</dc:creator>
      <dc:date>2024-06-07T16:24:53Z</dc:date>
    </item>
    <item>
      <title>Re: Using timedelta  to add days to a start date</title>
      <link>https://community.esri.com/t5/python-questions/using-timedelta-to-add-days-to-a-start-date/m-p/1487957#M70767</link>
      <description>&lt;P&gt;Thanks for reply Tom. Yep thats where I started also. Got there in the end. In a roundabout way.&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;Survey_Data = arcpy.GetParameterAsText(0)     
Date_last_treatment = arcpy.GetParameterAsText(1)
AGrowth = arcpy.GetParameterAsText(2)
Initial_date=datetime.datetime.strptime(Date_last_treatment,'%d/%m/%Y')
Growth = int(AGrowth)
if Growth == 10:
    Ndays = 10
elif Growth == 20:
    Ndays = 20
N_date = Intial_date + datetime.timedelta(days = Ndays)
Start_date= datetime.datetime.strftime(N_date, '%d/%m/%Y')
Start_date1 = "timestamp'{}'".format(Start_date)
Where_Clause = "DateTimeUTC &amp;gt;= {}".format(Start_date1)
arcpy.management.SelectLayerByAttribute(Survey_Data, "NEW_SELECTION", Where_Clause)&lt;/LI-CODE&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2024 02:10:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-timedelta-to-add-days-to-a-start-date/m-p/1487957#M70767</guid>
      <dc:creator>JasmineSpring</dc:creator>
      <dc:date>2024-06-12T02:10:37Z</dc:date>
    </item>
  </channel>
</rss>

