<?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: Variable substitution not working for time date function relativedelta in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/variable-substitution-not-working-for-time-date/m-p/1247678#M66522</link>
    <description>&lt;LI-CODE lang="python"&gt;numMonths =  arcpy.GetParameterAsText(3)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You're inputting a string into relativeDelta. Try these:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;numMonths =  arcpy.GetParameter(3)

numMonths =  int(arcpy.GetParameterAsText(3))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 12 Jan 2023 16:50:09 GMT</pubDate>
    <dc:creator>JohannesLindner</dc:creator>
    <dc:date>2023-01-12T16:50:09Z</dc:date>
    <item>
      <title>Variable substitution not working for time date function relativedelta</title>
      <link>https://community.esri.com/t5/python-questions/variable-substitution-not-working-for-time-date/m-p/1247644#M66521</link>
      <description>&lt;P&gt;So, I'm guessing the &lt;STRONG&gt;&lt;EM&gt;relativedelta&lt;/EM&gt;&lt;/STRONG&gt; function just doesn't support a variable substitution for the integer part. I'm trying to substitute a user enter numeric parameter into the function and get the following error.&amp;nbsp; Does anyone know if there is a way to work around this using another function?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://dateutil.readthedocs.io/en/stable/relativedelta.html" target="_blank" rel="noopener"&gt;https://dateutil.readthedocs.io/en/stable/relativedelta.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;FYI, I'm trying to find all the assets in a feature class that have been sold during a user enter time period from todays date. e.g. if I wanted to find all the assets that have been sold within the past year I would enter 12 for the number of months.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, note the script works fine when I hard code in a numeric value for numMonths into the function.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for any help,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;Traceback (most recent call last):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;File "D:\GIS_Data\Contractors\Mark\Vetting Tools\FindParcelsSoldInPast.py", line 26, in &amp;lt;module&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;timesPast = (datetime.datetime.now() - relativedelta(months=numMonths)).strftime("%Y-%m-%d")&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;File "C:\Python27\ArcGIS10.8\lib\site-packages\dateutil\relativedelta.py", line 127, in __init__&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;raise ValueError("Non-integer years and months are "&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;ValueError: Non-integer years and months are ambiguous and not currently supported.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Import arcpy module
import arcpy
import datetime
from dateutil.relativedelta import relativedelta

## Parameters
workspace = arcpy.GetParameterAsText(0) #As type Workspace

getFeatureLayer = arcpy.GetParameterAsText(1) #As type feature layer

dateSoldField = arcpy.GetParameterAsText(2) #As type field

numMonths =  arcpy.GetParameterAsText(3) #As type Long


## Variables
timesPast = (datetime.datetime.now() - relativedelta(months=numMonths)).strftime("%Y-%m-%d")
SQL = "\"{}\" &amp;gt;= date \'{}\'".format(dateSoldField, timesPast)


## Geoprocessing:

arcpy.SelectLayerByAttribute_management(getFeatureLayer, "NEW_SELECTION", SQL)&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;</description>
      <pubDate>Thu, 12 Jan 2023 15:37:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/variable-substitution-not-working-for-time-date/m-p/1247644#M66521</guid>
      <dc:creator>MPach</dc:creator>
      <dc:date>2023-01-12T15:37:07Z</dc:date>
    </item>
    <item>
      <title>Re: Variable substitution not working for time date function relativedelta</title>
      <link>https://community.esri.com/t5/python-questions/variable-substitution-not-working-for-time-date/m-p/1247678#M66522</link>
      <description>&lt;LI-CODE lang="python"&gt;numMonths =  arcpy.GetParameterAsText(3)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You're inputting a string into relativeDelta. Try these:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;numMonths =  arcpy.GetParameter(3)

numMonths =  int(arcpy.GetParameterAsText(3))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jan 2023 16:50:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/variable-substitution-not-working-for-time-date/m-p/1247678#M66522</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-01-12T16:50:09Z</dc:date>
    </item>
    <item>
      <title>Re: Variable substitution not working for time date function relativedelta</title>
      <link>https://community.esri.com/t5/python-questions/variable-substitution-not-working-for-time-date/m-p/1247721#M66523</link>
      <description>&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":rolling_on_the_floor_laughing:"&gt;🤣&lt;/span&gt;LOL, Thank you&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/294341"&gt;@JohannesLindner&lt;/a&gt;&amp;nbsp; I thought that since I set the variable in the script parameters to be a type "Long" that it would already be an integer value.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jan 2023 18:45:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/variable-substitution-not-working-for-time-date/m-p/1247721#M66523</guid>
      <dc:creator>MPach</dc:creator>
      <dc:date>2023-01-12T18:45:16Z</dc:date>
    </item>
  </channel>
</rss>

