<?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: Passing Parameter as Text to Field Calculator Expression in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/passing-parameter-as-text-to-field-calculator/m-p/271293#M20984</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;dont have arc to test&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;xp = &lt;/SPAN&gt;&lt;SPAN class="string" style="color: blue; font-size: 9pt !important; font-family: Consolas, 'Courier New', Courier, mono, serif !important;"&gt;'arcpy.time.ParseDateTimeString(!DATETIME!)' + str(datetime.timedelta(days=D, hours=H, minutes=M))&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 10 May 2016 22:36:49 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2016-05-10T22:36:49Z</dc:date>
    <item>
      <title>Passing Parameter as Text to Field Calculator Expression</title>
      <link>https://community.esri.com/t5/python-questions/passing-parameter-as-text-to-field-calculator/m-p/271291#M20982</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;&lt;SPAN style="font-family: tahoma, arial, helvetica, sans-serif;"&gt;Hello All,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: tahoma, arial, helvetica, sans-serif;"&gt;I am working on creating a tool that will add or subtract time to a text field in a feature class. My thought process is that I will take the original feature class with text field "DATETIME", make a copy of the original feature class (extra step to preserve source data), add a field titled "TIME", and run a field calculator expression with user designated values in the calculator expression.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy as ap
import os
# Script Arguments
input_fc = ap.GetParameterAsText(0)
output_fc = ap.GetParameterAsText(1)
D = ap.GetParameterAsText(2)
H = ap.GetParameterAsText(3)
M = ap.GetParameterAsText(4)

# Create copy of input trajectory
ap.CopyFeatures_management(input_fc, output_fc)

# Create new field
ap.AddField_management(output_fc,"TIME", "TEXT", 50 )

# Calculate new time in new field
exp = 'arcpy.time.ParseDateTimeString(!DATETIME!) + datetime.timedelta(days=D, hours=H, minutes=M)'
ap.CalculateField_management(output_fc, "TIME", exp, "PYTHON_9.3" )

# Copy new time to DATETIME field
ap.CalculateField_management(output_fc, "DATETIME", "!TIME!", "PYTHON_9.3")&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I encounter the following error:&lt;/P&gt;&lt;P&gt;ExecuteError: ERROR 000539: Error running expression: arcpy.time.ParseDateTimeString(u"4/28/2016 2:45:00 AM") + datetime.timedelta(days=D, hours=H, minutes=M)&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "&amp;lt;expression&amp;gt;", line 1, in &amp;lt;module&amp;gt;&lt;/P&gt;&lt;P&gt;NameError: name 'D' is not defined&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What gives? &lt;SPAN style="font-family: tahoma, arial, helvetica, sans-serif;"&gt; I know that the entire workflow process works when I do all of the steps manually but I think the "GetParamterAsText" is what is throwing me off.&lt;/SPAN&gt; I am still relatively new to Python and Tool Building so its probably something pretty obvious.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance for the help!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:15:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/passing-parameter-as-text-to-field-calculator/m-p/271291#M20982</guid>
      <dc:creator>JudsonCrouch1</dc:creator>
      <dc:date>2021-12-11T13:15:56Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Parameter as Text to Field Calculator Expression</title>
      <link>https://community.esri.com/t5/python-questions/passing-parameter-as-text-to-field-calculator/m-p/271292#M20983</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;can you put some print statements in there before and after the exp line, I am not sure about the exp being in quotes since it isn't a code block or not concatenated until after it obtains its values.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 May 2016 21:48:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/passing-parameter-as-text-to-field-calculator/m-p/271292#M20983</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-05-10T21:48:22Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Parameter as Text to Field Calculator Expression</title>
      <link>https://community.esri.com/t5/python-questions/passing-parameter-as-text-to-field-calculator/m-p/271293#M20984</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;dont have arc to test&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;xp = &lt;/SPAN&gt;&lt;SPAN class="string" style="color: blue; font-size: 9pt !important; font-family: Consolas, 'Courier New', Courier, mono, serif !important;"&gt;'arcpy.time.ParseDateTimeString(!DATETIME!)' + str(datetime.timedelta(days=D, hours=H, minutes=M))&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 May 2016 22:36:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/passing-parameter-as-text-to-field-calculator/m-p/271293#M20984</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-05-10T22:36:49Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Parameter as Text to Field Calculator Expression</title>
      <link>https://community.esri.com/t5/python-questions/passing-parameter-as-text-to-field-calculator/m-p/271294#M20985</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the replies Dan.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;While this eliminated the original error, I am now getting the following:&lt;/P&gt;&lt;P&gt;exp = "arcpy.time.ParseDateTimeString(!DATETIME!)" + str(datetime.timedelta(days=D, hours=H, minutes=M))&lt;/P&gt;&lt;P&gt;TypeError: unsupported type for timedelta minutes component: unicode&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I did a quick scour of Google and could not find anything of use. Any idea why unicode text would throw it off?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 May 2016 12:48:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/passing-parameter-as-text-to-field-calculator/m-p/271294#M20985</guid>
      <dc:creator>JudsonCrouch1</dc:creator>
      <dc:date>2016-05-11T12:48:01Z</dc:date>
    </item>
    <item>
      <title>Re: Passing Parameter as Text to Field Calculator Expression</title>
      <link>https://community.esri.com/t5/python-questions/passing-parameter-as-text-to-field-calculator/m-p/271295#M20986</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I figured it out. The unicode the error was referring to was the variable names (D,H,M). Instead of defining the variables ahead of time, I inserted the GetParamterAsText(x) into the corresponding argument in the timedelta expression.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Calculate new time in new field
xp = 'arcpy.time.ParseDateTimeString(!TIME!) + datetime.timedelta(days=int(arcpy.GetParameterAsText(2)), hours=int(arcpy.GetParameterAsText(3)), minutes=int(arcpy.GetParameterAsText(4)))'&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:15:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/passing-parameter-as-text-to-field-calculator/m-p/271295#M20986</guid>
      <dc:creator>JudsonCrouch1</dc:creator>
      <dc:date>2021-12-11T13:15:58Z</dc:date>
    </item>
  </channel>
</rss>

