Hello,
Please help me how to convert DD.MM.YYYY stored as Text format to YYYY/MM/DD as Date format using ArcGIS Pro Calculate Field?
Solved! Go to Solution.
Hi, the Convert Time Field geoprocessing tool is another option.
EDIT: Updated the code. I forgot that the Date function uses a zero based month. Thanks, @KenBuja !
Date Functions | ArcGIS Arcade
To convert your strings to dates: calculate date field, switch to Arcade
if(IsEmpty($feature.DateText)) {
return null
}
var date_split = Split($feature.DateText, ".")
return Date(date_split[2], date_split[1] - 1, date_split[0])
To change how the date is displayed in the table:
https://pro.arcgis.com/en/pro-app/latest/help/data/tables/format-numeric-and-date-fields.htm
Please note that this will give you an incorrect date, since the Month value in the Date function is 0-based. Use this instead.
if(IsEmpty($feature.DateText)) {
return null
}
var date_split = Split($feature.datetext, ".")
return Date( date_split[2], date_split[1] - 1, date_split[0])
Hi @KenBuja ,
Thank you for your response, I also try your script:
if(IsEmpty($feature.DateText)) {
return null
}
var date_split = Split($feature.datetext, ".")
return Date( date_split[2], date_split[1] - 1, date_split[0])
and give me this result:
You have to set the time zone for your layer since it defaults to GMT. Your time zone is seven hours off.
Python:
# expression
f(!DTFIELD!)
# code block - assuming "yyyy.mm.dd"
def f(dt):
try:
d = dt.split(".")
return datetime.datetime(int(d[2]), int(d[0], int(d[1])
except:
return None
ArcGIS Pro Help: Calculate Field Python Examples - Dates
Hi, the Convert Time Field geoprocessing tool is another option.
Hi @TimOrmsby
Thank you for the solution. With this geoprocessing tool I don't need to run a script.
This is the result: