<?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: Accessing attribute table datetime.datetime field in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/accessing-attribute-table-datetime-datetime-field/m-p/1383372#M69899</link>
    <description>&lt;P&gt;Use &lt;A href="https://docs.python.org/3/library/datetime.html#datetime.datetime.strftime" target="_self"&gt;strftime()&lt;/A&gt; and the formatting codes to get the date/time formatted however you like.&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.python.org/3/library/datetime.html#format-codes" target="_blank"&gt;datetime — Basic date and time types — Python 3.12.2 documentation&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 16 Feb 2024 14:59:54 GMT</pubDate>
    <dc:creator>BlakeTerhune</dc:creator>
    <dc:date>2024-02-16T14:59:54Z</dc:date>
    <item>
      <title>Accessing attribute table datetime.datetime field</title>
      <link>https://community.esri.com/t5/python-questions/accessing-attribute-table-datetime-datetime-field/m-p/1383355#M69898</link>
      <description>&lt;P&gt;Hey everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset that has a field in the attribute table that contains datetime information. I am writing a script that selects three layers, copies them, delete extra fields and then exports the tables to an excel file. Everything I have written works correctly but the last bit is what I cannot figure out. The excel file name needs to end with the date the data was last updated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently in the attribute table there is a field called dataload_date which contains datetime information for when it was last updated. using this code:&lt;/P&gt;&lt;P&gt;field = "dataload_date"&lt;/P&gt;&lt;P&gt;testlist = []&lt;/P&gt;&lt;P&gt;with arcpy.da.SearchCursor(FeatureClass, field) as cursor:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;for row in cursor:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;testlist.append(str(row[0])[0:10])&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;print(testlist[0])&lt;/P&gt;&lt;P&gt;This prints out the the date like this 2024-01-31, I need this as a string so I can manipulate it into the correct format for my file name.&lt;/P&gt;&lt;P&gt;I am under the impression that this code is only supposed to access the first row and append that value as a string to position 0 of test list. But it appears it iterates through every row in the dataset and appends it to position 0.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="NJDEPBrandonMcAlister_0-1708094599731.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/95019i2B93AF6B27BF6688/image-size/medium?v=v2&amp;amp;px=400" role="button" title="NJDEPBrandonMcAlister_0-1708094599731.png" alt="NJDEPBrandonMcAlister_0-1708094599731.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What am I doing wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code Sample came from:&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/data-access/searchcursor-class.htm" target="_blank"&gt;https://pro.arcgis.com/en/pro-app/latest/arcpy/data-access/searchcursor-class.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 14:50:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/accessing-attribute-table-datetime-datetime-field/m-p/1383355#M69898</guid>
      <dc:creator>BrandonMcAlister</dc:creator>
      <dc:date>2024-02-16T14:50:00Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing attribute table datetime.datetime field</title>
      <link>https://community.esri.com/t5/python-questions/accessing-attribute-table-datetime-datetime-field/m-p/1383372#M69899</link>
      <description>&lt;P&gt;Use &lt;A href="https://docs.python.org/3/library/datetime.html#datetime.datetime.strftime" target="_self"&gt;strftime()&lt;/A&gt; and the formatting codes to get the date/time formatted however you like.&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.python.org/3/library/datetime.html#format-codes" target="_blank"&gt;datetime — Basic date and time types — Python 3.12.2 documentation&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 14:59:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/accessing-attribute-table-datetime-datetime-field/m-p/1383372#M69899</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2024-02-16T14:59:54Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing attribute table datetime.datetime field</title>
      <link>https://community.esri.com/t5/python-questions/accessing-attribute-table-datetime-datetime-field/m-p/1383418#M69900</link>
      <description>&lt;P&gt;cursors are designed to be cycled through, but if you want to just get some specific value, you can use one of the cursor methods to do this.&amp;nbsp; For example, I just want to see the first and last record in a searchcursor and print the values for those records.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
fc00 = r"C:/arcpro_npg/Project_npg/npgeom.gdb/Ontario_bounds"
cursor = arcpy.da.SearchCursor(fc00, "*")
arr = cursor._as_narray()
frst = arr[0]
last = arr[-1]
print(frst)
print(last)
(1, [7559161.79374897, 1165505.11516148], 1, 20317.03064811, 9434393.51428649)
(205, [6373274.3835835 , 2297409.28244488], 1, 939.16177869, 28359.60787187)&lt;/LI-CODE&gt;&lt;P&gt;I could get the field names etc, once I have the data, but that is another story.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# I forget the field names

arr.dtype.names
('OBJECTID', 'Shape', 'Diss_fld', 'Shape_Length', 'Shape_Area')

# what is the biggest polygon?

arr['Shape_Area'].max()
Out[20]: 1074121664275.803

# and so on&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 16 Feb 2024 15:37:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/accessing-attribute-table-datetime-datetime-field/m-p/1383418#M69900</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2024-02-16T15:37:27Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing attribute table datetime.datetime field</title>
      <link>https://community.esri.com/t5/python-questions/accessing-attribute-table-datetime-datetime-field/m-p/1383475#M69901</link>
      <description>&lt;P&gt;Thanks Dan that worked perfectly&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 16:39:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/accessing-attribute-table-datetime-datetime-field/m-p/1383475#M69901</guid>
      <dc:creator>BrandonMcAlister</dc:creator>
      <dc:date>2024-02-16T16:39:07Z</dc:date>
    </item>
  </channel>
</rss>

