<?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: Calculate field conditional statement using a date formula in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/calculate-field-conditional-statement-using-a-date/m-p/689669#M53444</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;PS I just tried it without import datetime and it still works (which makes sense&lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/plain.png" /&gt;)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 10 Feb 2016 23:43:25 GMT</pubDate>
    <dc:creator>MoyaCalvert</dc:creator>
    <dc:date>2016-02-10T23:43:25Z</dc:date>
    <item>
      <title>Calculate field conditional statement using a date formula</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-conditional-statement-using-a-date/m-p/689660#M53435</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I am using ArcGIS 10.3 to update a field with a numeric value that represents the elapsed time since the data was captured.&amp;nbsp; I can do this in a python script that I have attached to a model but I also want to be able to sometimes do it quickly from within ArcGIS desktop and I am stumped.&lt;/P&gt;&lt;P&gt;I have written a 3 step process:&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;1. Create an integer field then calculate the number of days since today (field name = ET):&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;In Field Calculator, ET =&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;(datetime.datetime.now() - arcpy.time.ParseDateTimeString(!ActivityDate!)).days&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;2.&amp;nbsp; Create a conditional Statement for "Elapsed Time" field as follows:&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;Expression:&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;Reclass(!ET!)&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;def Reclass(ET):&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ( ET &amp;lt; 28):&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 1&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif ( ET&amp;gt;= 28 and ET &amp;lt; 91):&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 2&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif ( ET &amp;gt;= 91 and ET &amp;lt; 182):&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 3&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif ( ET &amp;gt;= 182 and ET &amp;lt; 365):&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 4&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif (ET &amp;gt;= 365):&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 5&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;3. Delete the ET field&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I really just want to declare a variable in my conditional statement for ET which would save having to create then delete the ET field, but everything I have tried does not work, for example:&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;Expression:&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;Reclass(ET)&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;ET = (datetime.datetime.now() - arcpy.time.ParseDateTimeString(!ActivityDate!)).days&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;def Reclass(ET):&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ( ET &amp;lt; 28):&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 1&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;etc etc&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I cannot find any examples of conditional statements that use a variable instead of a field value in the Field Calculator, so any help would be appreciated. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Feb 2016 06:25:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-conditional-statement-using-a-date/m-p/689660#M53435</guid>
      <dc:creator>MoyaCalvert</dc:creator>
      <dc:date>2016-02-10T06:25:26Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate field conditional statement using a date formula</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-conditional-statement-using-a-date/m-p/689661#M53436</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;And what errors are you getting?&lt;/P&gt;&lt;P&gt;Have you imported the datetime module?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Feb 2016 06:39:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-conditional-statement-using-a-date/m-p/689661#M53436</guid>
      <dc:creator>NeilAyres</dc:creator>
      <dc:date>2016-02-10T06:39:53Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate field conditional statement using a date formula</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-conditional-statement-using-a-date/m-p/689662#M53437</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The error says Error 000989: Python syntax error: Parsing error SyntaxError: invalid syntax (line 1).&lt;/P&gt;&lt;P&gt;I dont import the datetime module in Field Calculator.&lt;/P&gt;&lt;P&gt;The code for calculating the difference between today and and the collection day as an integer value works fine in Field calculator&amp;nbsp; but its not happy when you try to create a variable using the same code.&lt;IMG alt="ETError.PNG" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/180236_ETError.PNG" style="width: 620px; height: 114px;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Feb 2016 06:55:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-conditional-statement-using-a-date/m-p/689662#M53437</guid>
      <dc:creator>MoyaCalvert</dc:creator>
      <dc:date>2016-02-10T06:55:37Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate field conditional statement using a date formula</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-conditional-statement-using-a-date/m-p/689663#M53438</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;you need to import datetime... just put it in front of the def line&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Feb 2016 09:08:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-conditional-statement-using-a-date/m-p/689663#M53438</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-02-10T09:08:15Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate field conditional statement using a date formula</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-conditional-statement-using-a-date/m-p/689664#M53439</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;... and if it is not the missing import statement, you may want to look at the content of the field &lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;!ActivityDate!. If the content is not valid and cannot be parsed to a datetime it will fail at &lt;/SPAN&gt;&lt;EM style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;arcpy.time.ParseDateTimeString(!ActivityDate!)&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Feb 2016 11:25:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-conditional-statement-using-a-date/m-p/689664#M53439</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2016-02-10T11:25:07Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate field conditional statement using a date formula</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-conditional-statement-using-a-date/m-p/689665#M53440</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Unfortunately the import datetime does not work - I'm still getting the same error.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;just to re-iterate, I am using arcGIS 10.3 desktop and am using the Calculate Field tool.&lt;/P&gt;&lt;P&gt;The code now looks like this (but doesn't work):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; import datetime&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ET = (datetime.datetime.now() - arcpy.time.ParseDateTimeString(!ActivityDate!)).days&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; def Reclass(ET):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (ET &amp;lt; 28):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif (ET &amp;gt;= 28 and ET &amp;lt; 91):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif (ET &amp;gt;= 91 and ET &amp;lt; 182):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif (ET &amp;gt;= 182 and ET &amp;lt; 365):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif (ET &amp;gt;= 365):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 5&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;!ActivityDate! content does contain valid date values and the code string &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (datetime.datetime.now() - arcpy.time.ParseDateTimeString(!ActivityDate!)).days &lt;/P&gt;&lt;P&gt;works fine on its own, just wont work when I use it in this context.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;IMG alt="ETError2.PNG" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/180589_ETError2.PNG" style="height: auto;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Feb 2016 23:09:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-conditional-statement-using-a-date/m-p/689665#M53440</guid>
      <dc:creator>MoyaCalvert</dc:creator>
      <dc:date>2016-02-10T23:09:36Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate field conditional statement using a date formula</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-conditional-statement-using-a-date/m-p/689666#M53441</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;ET should be inside the def, just after it&lt;/P&gt;&lt;P&gt;def Reclass(a_fld)&lt;/P&gt;&lt;P&gt;ET = blah blah blah ...TimeString( a_fld )&lt;/P&gt;&lt;P&gt;Reclass(!ActivityDate! ) should be in the timelapesed = box&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You pass a field to the function&lt;/P&gt;&lt;P&gt;The function will contain a variable name, it shouldn't be the actual field name&lt;/P&gt;&lt;P&gt;your ET function should be within the def block not before&lt;/P&gt;&lt;P&gt;You should really parse the ET function into&lt;/P&gt;&lt;P&gt;nowww = (datetime.datetime.now()&amp;nbsp;&amp;nbsp; # before the code block&lt;/P&gt;&lt;P&gt;ET = (nowww - the reset of the original equation)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Feb 2016 23:20:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-conditional-statement-using-a-date/m-p/689666#M53441</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-02-10T23:20:19Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate field conditional statement using a date formula</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-conditional-statement-using-a-date/m-p/689667#M53442</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;OK thanks will try that&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Feb 2016 23:24:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-conditional-statement-using-a-date/m-p/689667#M53442</guid>
      <dc:creator>MoyaCalvert</dc:creator>
      <dc:date>2016-02-10T23:24:47Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate field conditional statement using a date formula</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-conditional-statement-using-a-date/m-p/689668#M53443</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;OK thanks Dan! Below is what worked.&amp;nbsp; (It didnt work if I parsed the ET function into nowww before the def block though). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;Expression:&lt;/P&gt;&lt;P style="padding-left: 30px; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;Reclass(!ActivityDate!)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; import datetime&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; def Reclass(DateFld):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ET = (datetime.datetime.now() - arcpy.time.ParseDateTimeString(DateFld)).days&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (ET &amp;lt; 28):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif (ET &amp;gt;= 28 and ET &amp;lt; 91):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif (ET &amp;gt;= 91 and ET &amp;lt; 182):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif (ET &amp;gt;= 182 and ET &amp;lt; 365):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif (ET &amp;gt;= 365):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 5&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Feb 2016 23:41:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-conditional-statement-using-a-date/m-p/689668#M53443</guid>
      <dc:creator>MoyaCalvert</dc:creator>
      <dc:date>2016-02-10T23:41:02Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate field conditional statement using a date formula</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-conditional-statement-using-a-date/m-p/689669#M53444</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;PS I just tried it without import datetime and it still works (which makes sense&lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/plain.png" /&gt;)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Feb 2016 23:43:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-conditional-statement-using-a-date/m-p/689669#M53444</guid>
      <dc:creator>MoyaCalvert</dc:creator>
      <dc:date>2016-02-10T23:43:25Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate field conditional statement using a date formula</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-conditional-statement-using-a-date/m-p/689670#M53445</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Moya ... et al...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For future reference&lt;/P&gt;&lt;P&gt;Using either numpy or the bisect module makes things much simpler when trying to do a sequential value reclassification ... whether it be text or numbers.&amp;nbsp; Some thoughts and brief tests, before put into functions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
dts = [1,28,29,91,92,182,183,365,366]
bins = [28,91,182,365,400]
&lt;/PRE&gt;&lt;P&gt;#1&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import numpy as np
c = np.digitize(dts, bins, right=True) + 1
&lt;/PRE&gt;&lt;P&gt;result&amp;nbsp;&amp;nbsp;&amp;nbsp; list(c) = [1, 1, 2, 2, 3, 3, 4, 4, 5]&lt;/P&gt;&lt;P&gt;#2&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import bisect&amp;nbsp;&amp;nbsp; 
d = [ bisect.bisect_left(bins,i) + 1&amp;nbsp; for i in dts]
&lt;/PRE&gt;&lt;P&gt;results&amp;nbsp; ditto&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If these were put into a function they could do the reclassification for you. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the examples here, a value of 1 was added to the returned indices to produce your new classification scheme. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The example #2 could be modified to turn it into a generator from a list comprehension. &lt;/P&gt;&lt;P&gt;I will post more on my blog when I get some more time and report back here.&amp;nbsp; These nested, multilevel if, else if, adnauseum, else statements have to go .&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 05:01:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-conditional-statement-using-a-date/m-p/689670#M53445</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-12T05:01:34Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate field conditional statement using a date formula</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-conditional-statement-using-a-date/m-p/689671#M53446</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The final link with code blocks using numpy and bisect modules&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migration-blogpost/55515"&gt;List comprehensions 3 ...&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if - elif - elif - elif - else&amp;nbsp; free examples&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Feb 2016 11:47:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-conditional-statement-using-a-date/m-p/689671#M53446</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-02-11T11:47:17Z</dc:date>
    </item>
  </channel>
</rss>

