I quickly wrote this up for the Field Calculator. This will return a new string where your "-" character should be replaced.
Assumptions I am making on your data:
- Everything is DD/MM/YYYY
- Where there isn't a value, it is replaced with a non-numeric string
This uses the python parser in the Field Calculator. I suggest running the code on a new temporary field so if there are issues, it doesn't mess up your good data. You need to replace a few things in the script. Where you see the "INSERT VALUE..." you need to change that to a number for either day, month or year.
If you are very unfamiliar with how to use python in the Field Calculator, I suggest you read this ESRI article.
Be sure you watch the indentations of the python script when copy and pasting. Also, make sure you call the function in the *UniqueID = * section (from my image). Yours will have your temporary field name. Also, easiest to double-click your field when entering it into the dateCheck(!FIELDHERE!) so it inserts the ! points.
def dateCheck(inputDate):
newDate = ""
splitDate = inputDate.split("/")
if (splitDate[0].isdigit()):
newDate += splitDate[0]
else:
newDate += "INSERT VALUE FOR DAY"
#insert the separator
newDate += "/"
if (splitDate[1].isdigit()):
newDate += splitDate[1]
else:
newDate += "INSERT VALUE FOR MONTH"
#insert the separator
newDate += "/"
if (splitDate[2].isdigit()):
newDate += splitDate[2]
else:
newDate += "INSERT VALUE FOR YEAR"
#return the newly constructed date
return newDate
Basically, we are splitting your current date by the / character. Each of those gets stored into a list, which is accessible by the index (the 1,2,3 inside of the [] I am using).
Each of those values is checked against the python isdigit()
function to see if it is really a number, or if it is a character like "-". If it passes, it is returned and appended to our new string. If it doesn't pass, you need to fill in a replacement value to be inserted instead.
You will still need to run the tool to convert to a date. I only did the work with the string for now since there is already a tool to convert string to date. This could all have been done using python into a new date field, too.
I haven't tested this with data, but give it a shot. Do a bit of reading up on python, and it will definitely help you out with these little challenges. Post a comment if there are problems.