<?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: Convert Date to yyyymmdd string in field calculator with Python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/convert-date-to-yyyymmdd-string-in-field/m-p/616270#M48089</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Joshua - this helps thanks!&lt;/P&gt;&lt;P&gt;I wasnt putting the datetime.datetwice&lt;/P&gt;&lt;P&gt;I&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 01 Jun 2019 21:16:01 GMT</pubDate>
    <dc:creator>NealBanerjee</dc:creator>
    <dc:date>2019-06-01T21:16:01Z</dc:date>
    <item>
      <title>Convert Date to yyyymmdd string in field calculator with Python</title>
      <link>https://community.esri.com/t5/python-questions/convert-date-to-yyyymmdd-string-in-field/m-p/616266#M48085</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am stuck with syntax for what I think will be very easy task.&amp;nbsp; I have a feature class with a date field that I simply want to convert to a string field in yyyymmdd format, so that I can combine it with other fields to create a unique ID.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Id like to do this in a simple field calculator (in ArcMap) session with python&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried using the strftime method with simple expression but that doesnt work&amp;nbsp;&amp;nbsp; !mydatefield!.strftime('%Y%m%d').&amp;nbsp; I also tried a few other things but keep getting error&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated!&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Neal&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 May 2019 12:16:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-date-to-yyyymmdd-string-in-field/m-p/616266#M48085</guid>
      <dc:creator>NealBanerjee</dc:creator>
      <dc:date>2019-05-31T12:16:53Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Date to yyyymmdd string in field calculator with Python</title>
      <link>https://community.esri.com/t5/python-questions/convert-date-to-yyyymmdd-string-in-field/m-p/616267#M48086</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is kind of a long-winded answer, but it should give you the results you're looking for.&amp;nbsp; Since you did not specify, I assume your date field is in a format like this 5/31/2019.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;date &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; str&lt;SPAN class="string token"&gt;'5/31/2019'&lt;/SPAN&gt;
ds &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; date&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;split&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;
formatted &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; ds&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;2&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; ds&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; ds&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;

&lt;SPAN class="operator token"&gt;&amp;gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt; formatted
&lt;SPAN class="string token"&gt;'2019531'&lt;/SPAN&gt;‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:20:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-date-to-yyyymmdd-string-in-field/m-p/616267#M48086</guid>
      <dc:creator>MitchHolley1</dc:creator>
      <dc:date>2021-12-12T02:20:40Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Date to yyyymmdd string in field calculator with Python</title>
      <link>https://community.esri.com/t5/python-questions/convert-date-to-yyyymmdd-string-in-field/m-p/616268#M48087</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you are starting with an actual datetime field [dt]:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;"&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="" style="color: #101094; border: 0px; font-weight: inherit;"&gt;import&lt;/SPAN&gt;&lt;SPAN class="" style="border: 0px; font-weight: inherit;"&gt; datetime 
dt &lt;/SPAN&gt;&lt;SPAN class="" style="border: 0px; font-weight: inherit;"&gt;=&lt;/SPAN&gt;&lt;SPAN class="" style="border: 0px; font-weight: inherit;"&gt; datetime&lt;/SPAN&gt;&lt;SPAN class="" style="border: 0px; font-weight: inherit;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="border: 0px; font-weight: inherit;"&gt;datetime&lt;/SPAN&gt;&lt;SPAN class="" style="border: 0px; font-weight: inherit;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-weight: inherit;"&gt;2019&lt;/SPAN&gt;&lt;SPAN class="" style="border: 0px; font-weight: inherit;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="border: 0px; font-weight: inherit;"&gt;&lt;SPAN style="color: #393318;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #7d2727;"&gt;5&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="" style="border: 0px; font-weight: inherit;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="border: 0px; font-weight: inherit;"&gt; &lt;/SPAN&gt;&lt;SPAN style="border: 0px; color: #7d2727; font-weight: inherit;"&gt;31&lt;/SPAN&gt;&lt;SPAN class="" style="border: 0px; font-weight: inherit;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="border: 0px; font-weight: inherit;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-weight: inherit;"&gt;0&lt;/SPAN&gt;&lt;SPAN class="" style="border: 0px; font-weight: inherit;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="border: 0px; font-weight: inherit;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-weight: inherit;"&gt;0&lt;/SPAN&gt;&lt;SPAN class="" style="border: 0px; font-weight: inherit;"&gt;)&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;CODE&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;"&gt;dt&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;"&gt;strftime&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-weight: inherit; font-size: 13px;"&gt;'&lt;/SPAN&gt;&lt;/CODE&gt;&lt;CODE&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-weight: inherit; font-size: 13px;"&gt;%Y%m%d&lt;/SPAN&gt;&lt;/CODE&gt;&lt;CODE&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-weight: inherit; font-size: 13px;"&gt;'&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P style="color: #242729; background-color: #ffffff; border: 0px; margin: 0px 0px 1em;"&gt;or&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-weight: inherit; font-size: 13px;"&gt;'{:%Y%m%d}'&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;"&gt;format&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;"&gt;dt&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P style="color: #242729; background-color: #ffffff; border: 0px; margin: 0px 0px 1em;"&gt;For completeness' sake: you can also directly access the attributes of the object, but then you only get the numbers:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;CODE&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-weight: inherit; font-size: 13px;"&gt;'%Y%m%d&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/CODE&gt;&lt;CODE&gt;&lt;SPAN class="" style="color: #7d2727; border: 0px; font-weight: inherit; font-size: 13px;"&gt;'&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;"&gt;%&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;"&gt; &lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;"&gt;(&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;"&gt;dt&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;"&gt;month&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;"&gt; dt&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;"&gt;day&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;"&gt;,&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;"&gt; dt&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;"&gt;year&lt;/SPAN&gt;&lt;SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;"&gt;)&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;HR style="color: #d6d9dc; background-color: #d6d9dc; border: 0px; margin-bottom: 20px;" /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;For reference, here are the codes used in format string:

%a&amp;nbsp;Weekday as locale’s abbreviated name.
%A&amp;nbsp;Weekday as locale’s full name.
%w&amp;nbsp;Weekday as a decimal number, where 0 is Sunday and 6 is Saturday.
%d&amp;nbsp;Day of the month as a zero-padded decimal number.
%b&amp;nbsp;Month as locale’s abbreviated name.
%B&amp;nbsp;Month as locale’s full name.
%m&amp;nbsp;Month as a zero-padded decimal number. 01, ..., 12
%y&amp;nbsp;Year without century as a zero-padded decimal number. 00, ..., 99
%Y&amp;nbsp;Year with century as a decimal number. 1970, 1988, 2001, 2013
%H&amp;nbsp;Hour (24-hour clock) as a zero-padded decimal number. 00, ..., 23
%I&amp;nbsp;Hour (12-hour clock) as a zero-padded decimal number. 01, ..., 12
%p&amp;nbsp;Locale’s equivalent of either AM or PM.
%M&amp;nbsp;Minute as a zero-padded decimal number. 00, ..., 59
%S&amp;nbsp;Second as a zero-padded decimal number. 00, ..., 59
%f&amp;nbsp;Microsecond as a decimal number, zero-padded on the left. 000000, ..., 999999
%z&amp;nbsp;UTC offset in the form +HHMM or -HHMM (empty if naive), +0000, -0400, +1030
%Z&amp;nbsp;Time zone name (empty if naive), UTC, EST, CST
%j&amp;nbsp;Day of the year as a zero-padded decimal number. 001, ..., 366
%U&amp;nbsp;Week number of the year (Sunday is the first) as a zero padded decimal number.
%W&amp;nbsp;Week number of the year (Monday is first) as a decimal number.
%c&amp;nbsp;Locale’s appropriate date and time representation.
%x&amp;nbsp;Locale’s appropriate date representation.
%X&amp;nbsp;Locale’s appropriate time representation.
%%&amp;nbsp;A literal '%' character.
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:20:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-date-to-yyyymmdd-string-in-field/m-p/616268#M48087</guid>
      <dc:creator>TedKowal</dc:creator>
      <dc:date>2021-12-12T02:20:42Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Date to yyyymmdd string in field calculator with Python</title>
      <link>https://community.esri.com/t5/python-questions/convert-date-to-yyyymmdd-string-in-field/m-p/616269#M48088</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It always helps to provide the specific errors and tracebacks you are getting.&amp;nbsp; There are so many possible errors that just saying you are getting an error isn't helpful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In ArcMap, cursors and the field calculator return date fields as text/unicode, so you have to be aware of that when trying to process the date information.&amp;nbsp; So you may need something like:&lt;/P&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;datetime&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;datetime&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;strptime&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt; !DateField!&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'%m/%d/%Y'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;strftime&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'%Y%m%d'&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>Fri, 31 May 2019 18:48:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-date-to-yyyymmdd-string-in-field/m-p/616269#M48088</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2019-05-31T18:48:05Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Date to yyyymmdd string in field calculator with Python</title>
      <link>https://community.esri.com/t5/python-questions/convert-date-to-yyyymmdd-string-in-field/m-p/616270#M48089</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Joshua - this helps thanks!&lt;/P&gt;&lt;P&gt;I wasnt putting the datetime.datetwice&lt;/P&gt;&lt;P&gt;I&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 01 Jun 2019 21:16:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-date-to-yyyymmdd-string-in-field/m-p/616270#M48089</guid>
      <dc:creator>NealBanerjee</dc:creator>
      <dc:date>2019-06-01T21:16:01Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Date to yyyymmdd string in field calculator with Python</title>
      <link>https://community.esri.com/t5/python-questions/convert-date-to-yyyymmdd-string-in-field/m-p/616271#M48090</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I made this function for adding a string date field. Hope it helps someone:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;DIV style="color: #bababa; background-color: #000000; font-weight: normal; font-size: 14px;"&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;def&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;addStringDate&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;gdbname&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;tablename&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;datefieldname&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddField_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;in_table&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;gdbname&lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"/"&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt;tablename&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; field_name&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;datefieldname&lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"_STR"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; field_type&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"TEXT"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; field_precision&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;""&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; field_scale&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;""&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; field_length&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"10"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; field_alias&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;""&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; field_is_nullable&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"NULLABLE"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; field_is_required&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"NON_REQUIRED"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; field_domain&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;""&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;CalculateField_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;in_table&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;gdbname&lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"/"&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt;tablename&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; field&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;datefieldname&lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"_STR"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; expression&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"arcpy.time.ParseDateTimeString( !"&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt;datefieldname&lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"!).strftime('%Y%m%d')"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; expression_type&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"PYTHON"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; code_block&lt;SPAN class="operator 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;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 02:20:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-date-to-yyyymmdd-string-in-field/m-p/616271#M48090</guid>
      <dc:creator>davidround</dc:creator>
      <dc:date>2021-12-12T02:20:45Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Date to yyyymmdd string in field calculator with Python</title>
      <link>https://community.esri.com/t5/python-questions/convert-date-to-yyyymmdd-string-in-field/m-p/616272#M48091</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;With Field Calculator (python parser) you can convert a string field from a format using YYYYMMDD (example 20190522) to a date field (5/22/2019) using this expression:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;(datetime.datetime.strptime( !OwnershipDate!,'%Y%m%d')).strftime('%m/%d/%Y')&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My field named OwnershipDate is formatted as a string with values YYYYMMDD, in this example 20190522.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;My reply is a bit redundant but after reading though many forum posts, everyone had slightly different requirements so the other examples threw me off.&amp;nbsp; This is for people who want to do what I specifically needed: &amp;nbsp; To calculate a date field from a string field formatted YYYYMMDD. Hope this adds clarity and helps someone!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Jun 2019 17:05:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-date-to-yyyymmdd-string-in-field/m-p/616272#M48091</guid>
      <dc:creator>JeffDuMez1</dc:creator>
      <dc:date>2019-06-12T17:05:23Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Date to yyyymmdd string in field calculator with Python</title>
      <link>https://community.esri.com/t5/python-questions/convert-date-to-yyyymmdd-string-in-field/m-p/616273#M48092</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Be aware that cursors and field calculator return actual datetime objects in ArcGIS Pro.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Jun 2019 17:49:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-date-to-yyyymmdd-string-in-field/m-p/616273#M48092</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2019-06-12T17:49:31Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Date to yyyymmdd string in field calculator with Python</title>
      <link>https://community.esri.com/t5/python-questions/convert-date-to-yyyymmdd-string-in-field/m-p/1153312#M64036</link>
      <description>&lt;P&gt;Appears to return strings in Pro python though.&amp;nbsp; Thanks very helpful posts!&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 12:38:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/convert-date-to-yyyymmdd-string-in-field/m-p/1153312#M64036</guid>
      <dc:creator>DavidTillberg_community</dc:creator>
      <dc:date>2022-03-14T12:38:21Z</dc:date>
    </item>
  </channel>
</rss>

