<?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: Populate date field with any chosen date within a python script in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/populate-date-field-with-any-chosen-date-within-a/m-p/517925#M40582</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Randy! Thanks very much for your answer!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am using PyCharm 2018.3.3 and ArcGIS Pro 10.5 with a File GDB&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My current attempt is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;import arcpy&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;import datetime&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;arcpy.env.workspace = r"xxxx.gdb"&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;arcpy.env.overwriteOutput = True&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;datefrom = datetime.datetime(2019,01,17)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;dateto = datetime.datetime(2020,01,01)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;arcpy.MakeFeatureLayer_management("L_LISTED_BUILDINGS", "LISTED_BUILDINGS")&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;A_OP_LISTBUILDINGS = arcpy.SelectLayerByLocation_management('LISTED_BUILDINGS', 'INTERSECT', 'FEATURE', 0, 'NEW_SELECTION')&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;A_OP_LISTBUILDINGS = arcpy.CalculateField_management(A_OP_LISTBUILDINGS,"DateFrom",datefrom)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;A_OP_LISTBUILDINGS = arcpy.CalculateField_management(A_OP_LISTBUILDINGS,"DateTo",dateto)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;arcpy.CopyFeatures_management(A_OP_LISTBUILDINGS, 'A_OP_190117_LISTBUILDINGS')&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However this populates the field with "00:00:00" i.e assuming it's a time. I think this is because it is in the format yyyy,mm,dd but that is the only format datetime.datetime accepts (I think).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 09 May 2019 07:43:33 GMT</pubDate>
    <dc:creator>RobMacDonald2</dc:creator>
    <dc:date>2019-05-09T07:43:33Z</dc:date>
    <item>
      <title>Populate date field with any chosen date within a python script</title>
      <link>https://community.esri.com/t5/python-questions/populate-date-field-with-any-chosen-date-within-a/m-p/517923#M40580</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all. I am trying to write a script in Python that will populate a date field in a featureclass with a date of my choosing. Not today's date. Can anybody point me in the right direction?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 May 2019 15:29:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/populate-date-field-with-any-chosen-date-within-a/m-p/517923#M40580</guid>
      <dc:creator>RobMacDonald2</dc:creator>
      <dc:date>2019-05-08T15:29:05Z</dc:date>
    </item>
    <item>
      <title>Re: Populate date field with any chosen date within a python script</title>
      <link>https://community.esri.com/t5/python-questions/populate-date-field-with-any-chosen-date-within-a/m-p/517924#M40581</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You should be familiar with&amp;nbsp;Python's &lt;A href="https://docs.python.org/2/library/datetime.html"&gt;datetime module&lt;/A&gt;&amp;nbsp;and&amp;nbsp;ArcGIS' &lt;A href="http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-functions/updatecursor.htm"&gt;Update Cursor&lt;/A&gt;&amp;nbsp;tool.&amp;nbsp; For a more specific answer, you should describe your work environment.&amp;nbsp; What version of Python and ArcGIS are you using?&amp;nbsp; What is the type of geodatabase?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 May 2019 16:31:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/populate-date-field-with-any-chosen-date-within-a/m-p/517924#M40581</guid>
      <dc:creator>RandyBurton</dc:creator>
      <dc:date>2019-05-08T16:31:36Z</dc:date>
    </item>
    <item>
      <title>Re: Populate date field with any chosen date within a python script</title>
      <link>https://community.esri.com/t5/python-questions/populate-date-field-with-any-chosen-date-within-a/m-p/517925#M40582</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Randy! Thanks very much for your answer!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am using PyCharm 2018.3.3 and ArcGIS Pro 10.5 with a File GDB&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My current attempt is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;import arcpy&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;import datetime&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;arcpy.env.workspace = r"xxxx.gdb"&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;arcpy.env.overwriteOutput = True&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;datefrom = datetime.datetime(2019,01,17)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;dateto = datetime.datetime(2020,01,01)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;arcpy.MakeFeatureLayer_management("L_LISTED_BUILDINGS", "LISTED_BUILDINGS")&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;A_OP_LISTBUILDINGS = arcpy.SelectLayerByLocation_management('LISTED_BUILDINGS', 'INTERSECT', 'FEATURE', 0, 'NEW_SELECTION')&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;A_OP_LISTBUILDINGS = arcpy.CalculateField_management(A_OP_LISTBUILDINGS,"DateFrom",datefrom)&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;A_OP_LISTBUILDINGS = arcpy.CalculateField_management(A_OP_LISTBUILDINGS,"DateTo",dateto)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;arcpy.CopyFeatures_management(A_OP_LISTBUILDINGS, 'A_OP_190117_LISTBUILDINGS')&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However this populates the field with "00:00:00" i.e assuming it's a time. I think this is because it is in the format yyyy,mm,dd but that is the only format datetime.datetime accepts (I think).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 May 2019 07:43:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/populate-date-field-with-any-chosen-date-within-a/m-p/517925#M40582</guid>
      <dc:creator>RobMacDonald2</dc:creator>
      <dc:date>2019-05-09T07:43:33Z</dc:date>
    </item>
    <item>
      <title>Re: Populate date field with any chosen date within a python script</title>
      <link>https://community.esri.com/t5/python-questions/populate-date-field-with-any-chosen-date-within-a/m-p/517926#M40583</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;First you need to create an expression value for the field calculation:&lt;/P&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;exp &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'datetime.datetime(2019,1,17).strftime("%Y/%m/%d")'&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;P&gt;&lt;/P&gt;&lt;P&gt;Then do the field calculation:&lt;/P&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;CalculateField_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;A_OP_LISTBUILDINGS&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"DateFrom"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;exp&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"PYTHON_9.3"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string 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>Thu, 09 May 2019 08:55:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/populate-date-field-with-any-chosen-date-within-a/m-p/517926#M40583</guid>
      <dc:creator>FC_Basson</dc:creator>
      <dc:date>2019-05-09T08:55:52Z</dc:date>
    </item>
    <item>
      <title>Re: Populate date field with any chosen date within a python script</title>
      <link>https://community.esri.com/t5/python-questions/populate-date-field-with-any-chosen-date-within-a/m-p/517927#M40584</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="" style="color: #000000; background: #f5f2f0; border: 0px; font-size: 14px; margin: 0.5em 0px; padding: 1em 1em 1em 3.8em;"&gt;&lt;CODE style="border: 0px; font-weight: inherit; font-size: 14px;"&gt;&lt;SPAN class="" style="color: #669900; border: 0px; font-weight: inherit; font-size: 14px;"&gt;.strftime("%Y/%m/%d")&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This was what i was missing!! Thanks so much! You legend&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 May 2019 09:08:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/populate-date-field-with-any-chosen-date-within-a/m-p/517927#M40584</guid>
      <dc:creator>RobMacDonald2</dc:creator>
      <dc:date>2019-05-09T09:08:41Z</dc:date>
    </item>
  </channel>
</rss>

