<?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: field calcs with substring in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/field-calcs-with-substring/m-p/51253#M4077</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you Joshua, that works.&amp;nbsp; Now I need to work on error-handling, as my data has a lot of null and '0' values that I need to have come through as null.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again for the Python&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 14 Oct 2020 12:16:35 GMT</pubDate>
    <dc:creator>JustinWolff</dc:creator>
    <dc:date>2020-10-14T12:16:35Z</dc:date>
    <item>
      <title>field calcs with substring</title>
      <link>https://community.esri.com/t5/python-questions/field-calcs-with-substring/m-p/51251#M4075</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a text field with date values in YYYYMMDD format.&amp;nbsp; I need to get them into the MM/DD/YYYY format in a text field (the target field for the MM/DD/YYYY values is text, not date).&amp;nbsp; The source field containing the YYYYMMDD values is named 'LastUpdateDate' and the target for the MM/DD/YYYY values is named 'CAMAUpdate'.&amp;nbsp; I'm attempting to use this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;SUBSTRING(!LastUpdateDate!,4,5)+'/'+SUBSTRING(!LastUpdateDate!,6,7)+'/'+SUBSTRING(!LastUpdateDate!,0,3)&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In Pro 2.6.2 it fails with:&lt;/P&gt;&lt;P&gt;ERROR 000539: Traceback (most recent call last):&lt;BR /&gt; File "&amp;lt;expression&amp;gt;", line 1, in &amp;lt;module&amp;gt;&lt;BR /&gt;NameError: name 'SUBSTRING' is not defined&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Source data is a polygon feature class in a file geodatabase.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Oct 2020 20:06:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calcs-with-substring/m-p/51251#M4075</guid>
      <dc:creator>JustinWolff</dc:creator>
      <dc:date>2020-10-13T20:06:37Z</dc:date>
    </item>
    <item>
      <title>Re: field calcs with substring</title>
      <link>https://community.esri.com/t5/python-questions/field-calcs-with-substring/m-p/51252#M4076</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The default expression type for Field Calculator in Pro is Python with the option to use Arcade.&amp;nbsp; You appear to trying to use SQL, which isn't a supported expression type.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Trying this using the Python expression type:&lt;/P&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;&lt;SPAN class="string token"&gt;"{}/{}/{}"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;!LastUpdateDate!&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;4&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;6&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; !LastUpdateDate!&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;6&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; !LastUpdateDate!&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;4&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Oct 2020 21:56:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calcs-with-substring/m-p/51252#M4076</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2020-10-13T21:56:23Z</dc:date>
    </item>
    <item>
      <title>Re: field calcs with substring</title>
      <link>https://community.esri.com/t5/python-questions/field-calcs-with-substring/m-p/51253#M4077</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you Joshua, that works.&amp;nbsp; Now I need to work on error-handling, as my data has a lot of null and '0' values that I need to have come through as null.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again for the Python&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Oct 2020 12:16:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calcs-with-substring/m-p/51253#M4077</guid>
      <dc:creator>JustinWolff</dc:creator>
      <dc:date>2020-10-14T12:16:35Z</dc:date>
    </item>
    <item>
      <title>Re: field calcs with substring</title>
      <link>https://community.esri.com/t5/python-questions/field-calcs-with-substring/m-p/51254#M4078</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The quickest way to get a result and move on is to make a selection against the table and filter out the records with NULL or 0.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can also use a Python ternary operator to check whether the LastUpdateField has 8 characters, which would indicate a full date.&lt;/P&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;&lt;SPAN class="string token"&gt;"{}/{}/{}"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;!LastUpdateDate!&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;4&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;6&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; !LastUpdateDate!&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;6&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; !LastUpdateDate!&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;4&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; len&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;!LastUpdateDate!&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;8&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt; None&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Oct 2020 15:00:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calcs-with-substring/m-p/51254#M4078</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2020-10-14T15:00:52Z</dc:date>
    </item>
    <item>
      <title>Re: field calcs with substring</title>
      <link>https://community.esri.com/t5/python-questions/field-calcs-with-substring/m-p/51255#M4079</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Josh - you're absolutely right, I was overthinking.&amp;nbsp; Thanks.&amp;nbsp; This is in a model anyway, so just selecting records that are not '0' or null, calculating and moving on is simple.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was attempting to use code block but not having any luck (see below) but it's no big deal because I'll just use a selection:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;def&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;X&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;LastUpdateDate&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; X &lt;SPAN class="keyword token"&gt;is&lt;/SPAN&gt; None&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'99/99/9999'&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;elif&lt;/SPAN&gt; X &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'0'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'99/99/9999'&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt; X &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"{}/{}/{}"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;!LastUpdateDate!&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;4&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;6&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; !LastUpdateDate!&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;6&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; !LastUpdateDate!&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;4&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; X‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:58:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calcs-with-substring/m-p/51255#M4079</guid>
      <dc:creator>JustinWolff</dc:creator>
      <dc:date>2021-12-10T21:58:45Z</dc:date>
    </item>
  </channel>
</rss>

