2

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.

5
  • Are you able to use arcpy?
    – Aaron
    Apr 19, 2022 at 16:34
  • 2
    In what format is the data that 03/19/198 is permitted? This isn't about the EGDB so much as it is about the source format.
    – Vince
    Apr 19, 2022 at 16:41
  • 2
    As said by @Vince if 03/19/198 is permitted you probably don't have a date field but more likely a text field if that the case you may just check for string less than 10 character (this of course will only find date with missing character, not other error...)
    – J.R
    Apr 19, 2022 at 16:44
  • no, it isnt permitted in the target geodatabase feature class it will kick up an invalid date entry Apr 19, 2022 at 17:02
  • @Vince @ J.R - sorry dont seem to be able edit my previous post to put these on Apr 19, 2022 at 17:45

1 Answer 1

2

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.

1
  • Thats perfect - thank you Mike! Apr 21, 2022 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.