AnsweredAssumed Answered

Calculate Field convert date to text

Question asked by ModernGIS on Dec 3, 2019
Latest reply on Dec 3, 2019 by ModernGIS


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.


Here is my code I have for converting the date-time to text:

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", "")


if I use the %B it comes out with the full month instead of the abbreviated month.


Thank You for your help