ArcMap – Date field

arcgis-desktoparcmapdatefield-calculatorpython-parser

I am trying to append some data to an existing enterprise geodatabase feature class, the data I am trying to append has a date field where some entries are in correct, eg instead of 03/19/1983 they have 03/19/198, this is throwing the append off as the enterprise geodatabase won't allow the append if the date is entered incorrectly.

Is there a field calculator snippet that can find these instances so I would be able to manually correct them?

There are like 20,000 records that I need to QC.

Best Answer

Here's one approach. Create a new integer-type field, and populate it using this code block:

from datetime import datetime

min_date = datetime(1900, 1, 1)
max_date = datetime.today()


def check_valid_date_str(s):
    try:
        dt = datetime.strptime(s, '%m/%d/%Y')
    except ValueError:
        return False
    return min_date <= dt <= max_date

and this expression:

check_valid_date_str(!YOUR_DATE_FIELD_NAME!)

This tries to parse the value into a date object. If it fails then it didn't match the expected format. If it succeeds, it makes sure it's within the expected range, which you can edit as necessary.

Then use select by attributes on that new field to highlight the issues.

This assumes your "date" field actually contains strings, which it seems to as pointed out in the comments above.

Related Question