<?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: How to test if a date is null in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-test-if-a-date-is-null/m-p/387158#M30560</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;SPAN style="font-family: inherit; line-height: 1.5;"&gt; It's as if python is not recognising the nulls as None.&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN style="font-family: inherit; line-height: 1.5;"&gt;I have confirmed this by commenting out the first part so it's just:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;if not row[1] is None:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[2] = "Y"
else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[2] = "N"
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And still the result is 'Y' for everything... &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How do date fields come across into Python? Are they datetime objects? Whatever type python sees them as, could it be converting the nulls to some other value (January 1st 1970 or something?)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 17:47:09 GMT</pubDate>
    <dc:creator>DanEvans</dc:creator>
    <dc:date>2021-12-11T17:47:09Z</dc:date>
    <item>
      <title>How to test if a date is null</title>
      <link>https://community.esri.com/t5/python-questions/how-to-test-if-a-date-is-null/m-p/387154#M30556</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am writing a python script geoprocessing tool and need to use an UpdateCursor to populate a text field with either 'Y' or 'N' depending on whether a date field is null or not. Here is my code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;with arcpy.da.UpdateCursor(arcpy.env.scratchGDB + r"/cn42n_table", (cn42n_status_field_validated, cn42n_cancel_date_field_validated, "CANC", "PARC")) as cursor:
&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if "CANC" in row[0] or not row[1] is None:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[2] = "Y"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[2] = "N"

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if "PARC" in row[0]:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[3] = "Y"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[3] = "N"&lt;/PRE&gt;&lt;P&gt;I have tried several ways of checking if row[1] (my date field) is not null but whatever I try the 'CANC' field is populated with a 'Y'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could someone please tell me the correct way to do this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:47:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-test-if-a-date-is-null/m-p/387154#M30556</guid>
      <dc:creator>DanEvans</dc:creator>
      <dc:date>2021-12-11T17:47:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to test if a date is null</title>
      <link>https://community.esri.com/t5/python-questions/how-to-test-if-a-date-is-null/m-p/387155#M30557</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Dan.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm not able to test it right now but, have you tried this?&lt;/P&gt;&lt;P&gt;&lt;SPAN class="keyword" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #006699;"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="keyword" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #006699;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN class="string" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: blue;"&gt;"CANC"&lt;/SPAN&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN class="keyword" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #006699;"&gt;in&lt;/SPAN&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000;"&gt; row[&lt;/SPAN&gt;&lt;SPAN class="number" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: green;"&gt;0&lt;/SPAN&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000;"&gt;] &lt;/SPAN&gt;&lt;SPAN class="keyword" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #006699;"&gt;or&lt;/SPAN&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN class="keyword" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #006699;"&gt;not&lt;/SPAN&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000;"&gt; row[&lt;/SPAN&gt;&lt;SPAN class="number" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: green;"&gt;1&lt;/SPAN&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000;"&gt;] &lt;/SPAN&gt;&lt;SPAN style="color: #006699; font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif;"&gt;== '#'&lt;/SPAN&gt;&lt;SPAN style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #000000;"&gt;:&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope it helps.&lt;/P&gt;&lt;P&gt;Luis&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Jan 2015 13:51:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-test-if-a-date-is-null/m-p/387155#M30557</guid>
      <dc:creator>Luis_ÁngelPascual_Camino</dc:creator>
      <dc:date>2015-01-15T13:51:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to test if a date is null</title>
      <link>https://community.esri.com/t5/python-questions/how-to-test-if-a-date-is-null/m-p/387156#M30558</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;if "CANC" is in row[0], row[2] will always equal "Y" because row[0] = "CANC" or (something that doesn't matter, first option is already true).&amp;nbsp; The only way that row[2] could = "N" is if row[0] is not "CANC" and row[1] has a date in it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think I've got my Y/N mixed up in the samples below, but these should give results similar to what you're looking for.&amp;nbsp; You've got your checking for a date code right and the script is doing what you're asking, it's your AND/OR logic that looks wonky.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;##------------------------&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="keyword"&gt;if&lt;/SPAN&gt; &lt;SPAN class="string"&gt;"CANC"&lt;/SPAN&gt; &lt;SPAN class="keyword"&gt;in&lt;/SPAN&gt; row[&lt;SPAN class="number"&gt;0&lt;/SPAN&gt;] &lt;SPAN class="keyword"&gt;and &lt;/SPAN&gt;row[&lt;SPAN class="number"&gt;1&lt;/SPAN&gt;] &lt;SPAN class="keyword"&gt;is&lt;/SPAN&gt; &lt;SPAN class="special"&gt;None&lt;/SPAN&gt;: &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[&lt;SPAN class="number"&gt;2] = &lt;SPAN class="string"&gt;"Y"&lt;/SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="keyword"&gt;elif&lt;/SPAN&gt; &lt;SPAN class="string"&gt;"CANC"&lt;/SPAN&gt; &lt;SPAN class="keyword"&gt;in&lt;/SPAN&gt; row[&lt;SPAN class="number"&gt;0&lt;/SPAN&gt;] &lt;SPAN class="keyword"&gt;and not (&lt;/SPAN&gt;row[&lt;SPAN class="number"&gt;1&lt;/SPAN&gt;] &lt;SPAN class="keyword"&gt;is&lt;/SPAN&gt; &lt;SPAN class="special"&gt;None)&lt;/SPAN&gt;:&lt;SPAN class="keyword"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[&lt;SPAN class="number"&gt;2] = &lt;SPAN class="string"&gt;"N"&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="number"&gt;&lt;SPAN class="string"&gt;else:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="number"&gt;&lt;SPAN class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Probably PARC"&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="number"&gt;&lt;SPAN class="string"&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="number"&gt;&lt;SPAN class="string"&gt;##---------------------------&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="number"&gt;&lt;SPAN class="string"&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="keyword"&gt;if&lt;/SPAN&gt; &lt;SPAN class="string"&gt;"CANC"&lt;/SPAN&gt; &lt;SPAN class="keyword"&gt;in&lt;/SPAN&gt; row[&lt;SPAN class="number"&gt;0&lt;/SPAN&gt;]:&lt;/P&gt;&lt;P&gt;&lt;SPAN class="keyword"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if r&lt;/SPAN&gt;ow[&lt;SPAN class="number"&gt;1&lt;/SPAN&gt;] &lt;SPAN class="keyword"&gt;is&lt;/SPAN&gt; &lt;SPAN class="special"&gt;None&lt;/SPAN&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[&lt;SPAN class="number"&gt;2] = &lt;SPAN class="string"&gt;"Y"&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="number"&gt;&lt;SPAN class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="number"&gt;&lt;SPAN class="string"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[2] = "N"&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="number"&gt;&lt;SPAN class="string"&gt;&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Jan 2015 14:24:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-test-if-a-date-is-null/m-p/387156#M30558</guid>
      <dc:creator>TimDine</dc:creator>
      <dc:date>2015-01-15T14:24:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to test if a date is null</title>
      <link>https://community.esri.com/t5/python-questions/how-to-test-if-a-date-is-null/m-p/387157#M30559</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Tim,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the suggestion. I don't think it's quite right for what I want though. Let me explain:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The dataset I'm working on is a table representing projects. One row in that table is one project. When a project is cancelled, the status has to be changed to include the string "CANC", and the cancel date field should be filled in. Unfortunately people sometimes forget to do one or the other, so I want to check if EITHER the Status field contains the string "CANC" OR the cancel date has a date in (is not null) OR both.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;row[0] is the status field&lt;/P&gt;&lt;P&gt;row[1] is the cancel date fields&lt;/P&gt;&lt;P&gt;row[2] is the CANC field (Y/N)&lt;/P&gt;&lt;P&gt;row[3] is the PARC field (Y/N)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;'PARC' is just another status meaning that the project is archived - that field gets populated correctly but the CANC field is all Y's, regardless of whether row[0] contains "CANC" or whether row[1] contains a date or is null. It's as if python is not recognising the nulls as None.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Jan 2015 14:36:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-test-if-a-date-is-null/m-p/387157#M30559</guid>
      <dc:creator>DanEvans</dc:creator>
      <dc:date>2015-01-15T14:36:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to test if a date is null</title>
      <link>https://community.esri.com/t5/python-questions/how-to-test-if-a-date-is-null/m-p/387158#M30560</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;SPAN style="font-family: inherit; line-height: 1.5;"&gt; It's as if python is not recognising the nulls as None.&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN style="font-family: inherit; line-height: 1.5;"&gt;I have confirmed this by commenting out the first part so it's just:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;if not row[1] is None:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[2] = "Y"
else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[2] = "N"
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And still the result is 'Y' for everything... &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How do date fields come across into Python? Are they datetime objects? Whatever type python sees them as, could it be converting the nulls to some other value (January 1st 1970 or something?)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:47:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-test-if-a-date-is-null/m-p/387158#M30560</guid>
      <dc:creator>DanEvans</dc:creator>
      <dc:date>2021-12-11T17:47:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to test if a date is null</title>
      <link>https://community.esri.com/t5/python-questions/how-to-test-if-a-date-is-null/m-p/387159#M30561</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, without going through everything, you could try testing if len(row[1]) &amp;lt; 1. You could also try printing row[1] in the loop. see what values it's finding. Or enclose row[1] is None in (), or even try Null instead of None, although I don't expect that to work. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If nothing else, these methods might give you some clue as to what's going on.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Jan 2015 15:55:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-test-if-a-date-is-null/m-p/387159#M30561</guid>
      <dc:creator>Zeke</dc:creator>
      <dc:date>2015-01-15T15:55:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to test if a date is null</title>
      <link>https://community.esri.com/t5/python-questions/how-to-test-if-a-date-is-null/m-p/387160#M30562</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ah! The problem was that the field parameter I was passing to ValidateFieldName was the status field again, not the cancel field!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the help anyway...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dan &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Jan 2015 15:57:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-test-if-a-date-is-null/m-p/387160#M30562</guid>
      <dc:creator>DanEvans</dc:creator>
      <dc:date>2015-01-15T15:57:29Z</dc:date>
    </item>
  </channel>
</rss>

