In ArcMap 10.4 I have the following code in Pre-Logic Script Code Section in Field Calculator with python option selected and show code block:

from datetime import datetime

def myfunction(date_text):
    if date_text != datetime.strptime(date_text, "%m/%d/%Y").strftime('%H:%M:%S'):
        return date_text
except ValueError:
        return None

And in bottom section for Field I want to update which is LAST_DATE_:


The code above works by instead checking if the value is a Time value. If it is then update the value works. However you will have to switch %d/%m/%Y to cover all your values. For some reason it would not add single digit day values.

  • 3
    You forgot to post what errors you're getting. It's difficult to help if we don't know what the errors actually are. By the way, it should be if and else, not If or Else. Python is case-sensitive. – Son of a Beach Sep 26 '19 at 22:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.