<?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: Converting date to string and combining fields using Python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/converting-date-to-string-and-combining-fields/m-p/406866#M32031</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Forgot you were using ArcGIS Pro, the code above was built on ArcMap.&amp;nbsp; I will take a look at what has changed with Pro and see if I can tweak the code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;UPDATE&lt;/STRONG&gt;:&amp;nbsp; Good news, Esri actually fixed the field calculator so it returns actual datetime objects instead of string representations of them.&amp;nbsp; The code is simpler with Pro:&lt;/P&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;&lt;SPAN class="string token"&gt;"{}_{:%Y%m%d_%H%M%S}"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt; !PARK_UNIT! &lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;!TRT_BEG_TM!&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>Fri, 06 Jul 2018 20:55:32 GMT</pubDate>
    <dc:creator>JoshuaBixby</dc:creator>
    <dc:date>2018-07-06T20:55:32Z</dc:date>
    <item>
      <title>Converting date to string and combining fields using Python</title>
      <link>https://community.esri.com/t5/python-questions/converting-date-to-string-and-combining-fields/m-p/406863#M32028</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to get more familiar with ArcGIS Pro and by necessity, Python. I have multiple feature classes that are assigned a unique identifier that combines the location and date/time that the data were collected in the format "PARK_YYYYMMDD_HHMMSS". "PARK" comes from a data field [Park_Unit] with a coded domain and date/time from a date field [TRT_BEG_TM]. I'm trying to get it to work using Python but I can't wrap my head around functions and syntax. Here's the VB Script expression I've been using in ArcMap for reference. Thanks in advance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Pre-Logic Script Code:&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;strYear= Year( [TRT_BEG_TM] )&lt;BR /&gt;strMonth= Month ( [TRT_BEG_TM] )&lt;BR /&gt;strDay = Day( [TRT_BEG_TM] )&lt;BR /&gt;strHour = Hour( [TRT_BEG_TM] )&lt;BR /&gt;strMin = Minute( [TRT_BEG_TM] )&lt;BR /&gt;strSec = Second( [TRT_BEG_TM] )&lt;BR /&gt;If strDay &amp;lt; 10 Then&lt;BR /&gt;&amp;nbsp; strDay = "0"&amp;amp; strDay&lt;BR /&gt;end if&lt;BR /&gt;&amp;nbsp; If strMonth &amp;lt; 10 Then&lt;BR /&gt; strMonth = "0" &amp;amp; strMonth&lt;BR /&gt;end if&lt;BR /&gt;If strHour &amp;lt; 10 Then&lt;BR /&gt;&amp;nbsp; strHour = "0" &amp;amp; strHour&lt;BR /&gt;end if&lt;BR /&gt;If strMin &amp;lt; 10 Then&lt;BR /&gt;&amp;nbsp; strMin = "0" &amp;amp; strMin&lt;BR /&gt;end if&lt;BR /&gt;If strSec &amp;lt; 10 Then&lt;BR /&gt;&amp;nbsp; strSec = "0" &amp;amp; strSec&lt;BR /&gt;end if&lt;BR /&gt;Formatteddate= strYear &amp;amp; strMonth &amp;amp; strDay &amp;amp; strHour &amp;amp; strMin &amp;amp; strSec&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;LOC_NM=&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;[PARK_UNIT] &amp;amp;"_"&amp;amp; left(Formatteddate,8) &amp;amp; "_" &amp;amp; right(Formatteddate,6)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jul 2018 20:10:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/converting-date-to-string-and-combining-fields/m-p/406863#M32028</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2018-07-06T20:10:17Z</dc:date>
    </item>
    <item>
      <title>Re: Converting date to string and combining fields using Python</title>
      <link>https://community.esri.com/t5/python-questions/converting-date-to-string-and-combining-fields/m-p/406864#M32029</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try this in the expression box of field calculator:&lt;/P&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;&lt;SPAN class="string token"&gt;"{}_{:%Y%m%d_%H%M%S}"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt; !PARK_UNIT! &lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;time&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ParseDateTimeString&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt; !TRT_BEG_TM!&lt;SPAN class="punctuation 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;P&gt;Unfortunately, and for reasons I don't understand, the field calculator returns datetimes as strings, which requires converting them back to &lt;SPAN style="font-family: courier new, courier, monospace;"&gt;datetime&lt;/SPAN&gt; using &lt;SPAN style="font-family: courier new, courier, monospace;"&gt;arcpy.time&lt;/SPAN&gt; if you want to use native Python datetime handling.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jul 2018 20:43:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/converting-date-to-string-and-combining-fields/m-p/406864#M32029</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2018-07-06T20:43:09Z</dc:date>
    </item>
    <item>
      <title>Re: Converting date to string and combining fields using Python</title>
      <link>https://community.esri.com/t5/python-questions/converting-date-to-string-and-combining-fields/m-p/406865#M32030</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Joshua, that expression returns the following error:&lt;/P&gt;&lt;P&gt;ERROR 000539: Traceback (most recent call last):&lt;BR /&gt; File "&amp;lt;expression&amp;gt;", line 1, in &amp;lt;module&amp;gt;&lt;BR /&gt; File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\time.py", line 300, in ParseDateTimeString&lt;BR /&gt; raise ValueError(datetime_string)&lt;BR /&gt;ValueError: 2018-06-28 15:27:48&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jul 2018 20:51:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/converting-date-to-string-and-combining-fields/m-p/406865#M32030</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2018-07-06T20:51:43Z</dc:date>
    </item>
    <item>
      <title>Re: Converting date to string and combining fields using Python</title>
      <link>https://community.esri.com/t5/python-questions/converting-date-to-string-and-combining-fields/m-p/406866#M32031</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Forgot you were using ArcGIS Pro, the code above was built on ArcMap.&amp;nbsp; I will take a look at what has changed with Pro and see if I can tweak the code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;UPDATE&lt;/STRONG&gt;:&amp;nbsp; Good news, Esri actually fixed the field calculator so it returns actual datetime objects instead of string representations of them.&amp;nbsp; The code is simpler with Pro:&lt;/P&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;&lt;SPAN class="string token"&gt;"{}_{:%Y%m%d_%H%M%S}"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt; !PARK_UNIT! &lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;!TRT_BEG_TM!&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>Fri, 06 Jul 2018 20:55:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/converting-date-to-string-and-combining-fields/m-p/406866#M32031</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2018-07-06T20:55:32Z</dc:date>
    </item>
    <item>
      <title>Re: Converting date to string and combining fields using Python</title>
      <link>https://community.esri.com/t5/python-questions/converting-date-to-string-and-combining-fields/m-p/406867#M32032</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Fantastic, that worked, thanks very much.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jul 2018 22:07:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/converting-date-to-string-and-combining-fields/m-p/406867#M32032</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2018-07-06T22:07:09Z</dc:date>
    </item>
  </channel>
</rss>

