Select to view content in your preferred language

Convert String field to Date Field

7567
13
Jump to solution
01-12-2021 02:00 PM
Labels (1)
DonovanC
New Contributor III

Does anyone have any suggestions on how I can convert this field into a date/time.  I converted it from kml to shp file and all the information was in one field. I tried using the Convert Time Field tool but it failed.

DonovanC_0-1610488594343.png

@XanderBakker 

@HusseinNasser2 

 

Tags (2)
0 Kudos
13 Replies
DonovanC
New Contributor III

Hi @XanderBakker 

I added in the two additional lines of the expressions but it does not pull the timestamp.

DonovanC_0-1610634768665.png

 

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi @DonovanC ,

 

As far as I understand, the way a date time is shown in ArcGIS Pro depends on the settings of your system: https://pro.arcgis.com/en/pro-app/latest/help/data/tables/date-fields.htm 

You can validate this using the pop-up and define an expression to return the date and time using the format that you want. An example: 

return Text($feature["Name of your date field"], "Y-MM-DD HH:mm:ss");
XanderBakker
Esri Esteemed Contributor

Hi @DonovanC ,

 

Earlier on you also mentioned using Python for the field calculation. This should return the same result.

 

def ParseDateTime(tst):
    import datetime
    dt_format1 = "%d-%m-%Y %H:%M:%S"
    dt_format2 = "%m/%d/%y %I:%M:%S %p"
    if "-" in tst:
        txt = tst[1:20]
        dt = datetime.datetime.strptime(txt, dt_format1)
        return dt
    else:
        txt = tst[1:21]
        dt = datetime.datetime.strptime(txt, dt_format2)
    return dt

 

ParseDateTime(!kml_des!)

 

XanderBakker_0-1610640055634.png

 

 

DonovanC
New Contributor III

Thanks for all your help!!

0 Kudos