I am using ArcGIS Pro 3.1.3. I have a field full of dates, stored as a text field, arranged in the format dd/mm/yyyy. I want to extract the month value and store in a newly created field as an integer. If I just put:
!DateField![3:5]
in the field calculator, without using a code block, the new month field becomes populated, like I want it. However, I only want to extract the values from the date field if the value if the criteria in a DateTypeField, which lists the date type of the record (whether it pertains to specific date, or date range e.g. year), are met. Most of the dates are marked "D" in the date type field and these are the ones I want to populate the new month field for. For all other values of DateTypeField, I want the value of the month field to remain null.
My expression in the Code Block looks like this:
def reclass(Date, DateType):
if (DateType == "D"):
Date[3:5]
With correct indentation, which is lost when copying and pasting into this box. The expression passes the validation check. Then I use the following field calculator expression:
reclass(!DateField!,!DateTypeField!)
And it runs, but all values in the table remain NULL. Can anyone see where I am going wrong? Many thanks.