<?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: Error with Dates when Adding Features with Python API in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/error-with-dates-when-adding-features-with-python/m-p/1591787#M63882</link>
    <description>&lt;P&gt;Came across this looking for something else doing something similar. I don't know if something that says "works on my machine" is helpful but everything seemed to upload for me doing the following:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="timestamp_update.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/126912i32239913C6141BED/image-size/large?v=v2&amp;amp;px=999" role="button" title="timestamp_update.png" alt="timestamp_update.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Maybe there's something up with tzlocal() not producing a timezone object?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 04 Mar 2025 17:22:24 GMT</pubDate>
    <dc:creator>JohnEvans6</dc:creator>
    <dc:date>2025-03-04T17:22:24Z</dc:date>
    <item>
      <title>Error with Dates when Adding Features with Python API</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/error-with-dates-when-adding-features-with-python/m-p/1590251#M63828</link>
      <description>&lt;P&gt;I'm getting the errors shown in the first screenshot below when trying to add features to a hosted feature layer using the Python API.&lt;/P&gt;&lt;P&gt;The features throwing the error all seem to have dates at or prior to 1/1/1900.&lt;/P&gt;&lt;P&gt;When constructing the JSON for the features to add, I'm assigning our local time zone to the datetime object.&amp;nbsp; Is there a different approach I should be taking to avoid these errors?&amp;nbsp; The second screenshot shows a sample of the dictionary key and value being used when trying to add features.&lt;/P&gt;&lt;P&gt;If I set any dates at or prior to the year 1900 to NoneType objects, the features are written to the hosted feature layer without errors.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mpboyle_0-1740680833659.png" style="width: 488px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/126558i99E9BB6A93645063/image-dimensions/488x210?v=v2" width="488" height="210" role="button" title="mpboyle_0-1740680833659.png" alt="mpboyle_0-1740680833659.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;'DateField': datetime.datetime(1900, 1, 1, 12, 0, tzinfo=tzlocal())&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Feb 2025 18:41:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/error-with-dates-when-adding-features-with-python/m-p/1590251#M63828</guid>
      <dc:creator>mpboyle</dc:creator>
      <dc:date>2025-02-27T18:41:48Z</dc:date>
    </item>
    <item>
      <title>Re: Error with Dates when Adding Features with Python API</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/error-with-dates-when-adding-features-with-python/m-p/1590610#M63843</link>
      <description>&lt;P&gt;Hey &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/189832"&gt;@mpboyle&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could try this function here to just return any date earlier than 1/1/1900 to None, as that's the normal null value in a DB for date columns:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from datetime import datetime

def safe_datetime(date):
    return date if date &amp;gt;= datetime(1900, 1, 1) else None

'DateField': safe_datetime(datetime(1899, 12, 31))&lt;/LI-CODE&gt;&lt;P&gt;In this case DateField will be None.&lt;/P&gt;&lt;P&gt;I think just setting to None will be one of the best bets here.&lt;/P&gt;&lt;P&gt;Cody&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2025 12:09:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/error-with-dates-when-adding-features-with-python/m-p/1590610#M63843</guid>
      <dc:creator>CodyPatterson</dc:creator>
      <dc:date>2025-02-28T12:09:50Z</dc:date>
    </item>
    <item>
      <title>Re: Error with Dates when Adding Features with Python API</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/error-with-dates-when-adding-features-with-python/m-p/1590655#M63845</link>
      <description>&lt;P&gt;I'm already handling the dates if they're prior to 1900 (code below).&amp;nbsp; I'm really wondering why I'm getting an error at all when trying to insert a feature with a date prior to 1900...are these dates not supported by the Python API?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def format_date(input_value):
    if isinstance(input_value, datetime.datetime):
        if input_value.year &amp;lt;= 1900:
            return None
        else:
            return input_value
    else:
        return None &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2025 14:02:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/error-with-dates-when-adding-features-with-python/m-p/1590655#M63845</guid>
      <dc:creator>mpboyle</dc:creator>
      <dc:date>2025-02-28T14:02:19Z</dc:date>
    </item>
    <item>
      <title>Re: Error with Dates when Adding Features with Python API</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/error-with-dates-when-adding-features-with-python/m-p/1591787#M63882</link>
      <description>&lt;P&gt;Came across this looking for something else doing something similar. I don't know if something that says "works on my machine" is helpful but everything seemed to upload for me doing the following:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="timestamp_update.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/126912i32239913C6141BED/image-size/large?v=v2&amp;amp;px=999" role="button" title="timestamp_update.png" alt="timestamp_update.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Maybe there's something up with tzlocal() not producing a timezone object?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Mar 2025 17:22:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/error-with-dates-when-adding-features-with-python/m-p/1591787#M63882</guid>
      <dc:creator>JohnEvans6</dc:creator>
      <dc:date>2025-03-04T17:22:24Z</dc:date>
    </item>
  </channel>
</rss>

