<?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: Calculate Field convert date to text in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/calculate-field-convert-date-to-text/m-p/734240#M56913</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&amp;nbsp;&lt;A href="https://community.esri.com/people/ModernGIS"&gt;ModernGIS&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sorry, my bad, it seems that I am mixing languages... The ".upper()" should be at the end of the expression. Something like this:&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;ELECTRIC_METER_READING_RAWDATA_VIEW&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"READING_DATE_TEXT_CONVERT"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"((datetime.datetime.strptime( !READING_DATE_TEXT! ,'%m/%d/%Y %H:%M:%S %p')).strftime('%b-%Y')).upper()"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"PYTHON"&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;P&gt;&lt;/P&gt;&lt;P&gt;Could you try again?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 03 Dec 2019 20:03:58 GMT</pubDate>
    <dc:creator>XanderBakker</dc:creator>
    <dc:date>2019-12-03T20:03:58Z</dc:date>
    <item>
      <title>Calculate Field convert date to text</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-convert-date-to-text/m-p/734237#M56910</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Greetings:&lt;/P&gt;&lt;P&gt;I have a python script written that has a small section that converts a date (11/5/2019) in date format into a text format (Nov-2019). The code is within a Calculate Field tool command and it works just fine. However, the end results of Nov-2019 is not exactly what I want. The end result that I am looking for is NOV-2019. Is there a way in the code that I can tell the tool to capitalize the month so it shows up as NOV-2019 instead of Nov-2019? OR is there a different command tool I need to add into my python script to change the month from lowercase to uppercase? Having a hard time finding the answer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is my code I have for converting the date-time to text:&lt;/P&gt;&lt;P&gt;arcpy.CalculateField_management(ELECTRIC_METER_READING_RAWDATA_VIEW, "READING_DATE_TEXT_CONVERT", "(datetime.datetime.strptime( !READING_DATE_TEXT! ,'%m/%d/%Y %H:%M:%S %p')).strftime('%b-%Y')", "PYTHON", "")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if I use the %B it comes out with the full month instead of the abbreviated month.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank You for your help&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Dec 2019 19:15:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-convert-date-to-text/m-p/734237#M56910</guid>
      <dc:creator>ModernElectric</dc:creator>
      <dc:date>2019-12-03T19:15:23Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field convert date to text</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-convert-date-to-text/m-p/734238#M56911</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&amp;nbsp;&lt;A href="https://community.esri.com/people/ModernGIS"&gt;ModernGIS&lt;/A&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you try this?&lt;/P&gt;&lt;PRE class="language-javascript line-numbers"&gt;&lt;CODE&gt;arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;CalculateField_management&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;ELECTRIC_METER_READING_RAWDATA_VIEW&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"READING_DATE_TEXT_CONVERT"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"upper((datetime.datetime.strptime( !READING_DATE_TEXT! ,'%m/%d/%Y %H:%M:%S %p')).strftime('%b-%Y'))"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"PYTHON"&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>Tue, 03 Dec 2019 19:35:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-convert-date-to-text/m-p/734238#M56911</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2019-12-03T19:35:09Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field convert date to text</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-convert-date-to-text/m-p/734239#M56912</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for the response. However, the code didn't seem to work. I copied it to my python script to replace the existing and ran the script. Got a response that said:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;NameError: name 'upper' is not defined&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Dec 2019 19:50:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-convert-date-to-text/m-p/734239#M56912</guid>
      <dc:creator>ModernElectric</dc:creator>
      <dc:date>2019-12-03T19:50:48Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field convert date to text</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-convert-date-to-text/m-p/734240#M56913</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&amp;nbsp;&lt;A href="https://community.esri.com/people/ModernGIS"&gt;ModernGIS&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sorry, my bad, it seems that I am mixing languages... The ".upper()" should be at the end of the expression. Something like this:&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;ELECTRIC_METER_READING_RAWDATA_VIEW&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"READING_DATE_TEXT_CONVERT"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"((datetime.datetime.strptime( !READING_DATE_TEXT! ,'%m/%d/%Y %H:%M:%S %p')).strftime('%b-%Y')).upper()"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"PYTHON"&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;P&gt;&lt;/P&gt;&lt;P&gt;Could you try again?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Dec 2019 20:03:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-convert-date-to-text/m-p/734240#M56913</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2019-12-03T20:03:58Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field convert date to text</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-convert-date-to-text/m-p/734241#M56914</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for the revision. That did the trick. So I can understand and possibly implement it into other scripts, how does putting the .upper() into the code block work? Are there other things that I can add in it's place for other variables and/or circumstances?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Dec 2019 20:28:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-convert-date-to-text/m-p/734241#M56914</guid>
      <dc:creator>ModernElectric</dc:creator>
      <dc:date>2019-12-03T20:28:11Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field convert date to text</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-convert-date-to-text/m-p/734242#M56915</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&amp;nbsp;&lt;A href="https://community.esri.com/migrated-users/8679"&gt;Modern Electric&lt;/A&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are a large number of "helpers" that you can use in the single line expression:&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/475196_pastedImage_1.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can also put your logic in the Code Block and import modules and do some really complex stuff. However,&amp;nbsp;when you feel the need to use code in the code block, you&amp;nbsp;might what to evaluate if it is not easier to create a stand alone script to do the processing and have more control over the process.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is some further reading:&amp;nbsp;&lt;A class="link-titled" href="https://pro.arcgis.com/en/pro-app/tool-reference/data-management/calculate-field-examples.htm" title="https://pro.arcgis.com/en/pro-app/tool-reference/data-management/calculate-field-examples.htm"&gt;Calculate Field Python examples—Data Management toolbox | ArcGIS Desktop&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Dec 2019 20:36:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-convert-date-to-text/m-p/734242#M56915</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2019-12-03T20:36:57Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field convert date to text</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-convert-date-to-text/m-p/734243#M56916</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank You for your help. I will do some more research to see how it may help some of my other scripts.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Dec 2019 20:40:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-convert-date-to-text/m-p/734243#M56916</guid>
      <dc:creator>ModernElectric</dc:creator>
      <dc:date>2019-12-03T20:40:12Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field convert date to text</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-convert-date-to-text/m-p/1011592#M59359</link>
      <description>&lt;P&gt;I am doing a follow-up on this solution you assisted with awhile ago, but this time for a different project. I am understanding the basics but still having some issues.&lt;/P&gt;&lt;P&gt;Lets say I have a DATE field that is populated from a different database. However, within the field the dates/times are produced differently. Some may be 2/25/2010 7:41:00 AM and others *In the Same Field* are 7/9/2008 *Missing the time*&lt;/P&gt;&lt;P&gt;When I run the script on the whole column and try to convert, it crashes due to different date formats.&amp;nbsp;&lt;/P&gt;&lt;P&gt;My goal is to get all of them into the Day of the Week, month day and year. I have figured out how to do that part but with (2) sometimes (3) different date formats, its not working. Is there a way to take ALL of the dates, regardless if they are different format and convert them ALL to the same format?&lt;/P&gt;&lt;P&gt;So, 2/25/2010 7:41:00 AM and 7/9/2008 with ONE command would change to Weekday, Month Day, Year?&lt;/P&gt;&lt;P&gt;I am stuck and my research isn't working.&lt;/P&gt;&lt;P&gt;Thank You&lt;/P&gt;</description>
      <pubDate>Mon, 21 Dec 2020 21:51:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-convert-date-to-text/m-p/1011592#M59359</guid>
      <dc:creator>ModernElectric</dc:creator>
      <dc:date>2020-12-21T21:51:28Z</dc:date>
    </item>
  </channel>
</rss>

