Lets say I have a DATE field that is populated from a different database. However, within the field the dates/times are produced differently. Some may be 2/25/2010 7:41:00 AM and others *In the Same Field* are 7/9/2008 *Missing the time*
When I run the script on the whole column and try to convert, it crashes due to different date formats.
My goal is to get all of them into the Day of the Week, month day and year. I have figured out how to do that part but with (2) sometimes (3) different date formats, its not working. Is there a way to take ALL of the dates, regardless if they are different format and convert them ALL to the same format?
So, 2/25/2010 7:41:00 AM and 7/9/2008 with ONE command would change to Weekday, Month Day, Year?
I am stuck and my research isn't working.
Thank You
Solved! Go to Solution.
produce a string field of the dates using this principle
d = ["2/25/2010 7:41:00 AM", "7/9/2008"]
[i.split(" ")[0] for i in d]
['2/25/2010', '7/9/2008']
# ---- field calculator perhaps ... str(!YourField!).split(" ")[0]
Convert Time Field (Data Management)—ArcGIS Pro | Documentation
for other information
produce a string field of the dates using this principle
d = ["2/25/2010 7:41:00 AM", "7/9/2008"]
[i.split(" ")[0] for i in d]
['2/25/2010', '7/9/2008']
# ---- field calculator perhaps ... str(!YourField!).split(" ")[0]
Convert Time Field (Data Management)—ArcGIS Pro | Documentation
for other information
BINGO. Dang Dan I sure wish I had your expertise.
Let me pick your brain one more time. This converts the DATE field to a different TEXT field. From here, how would I take the text field and convert the 12/12/2020 to Monday, December 21, 2020
I have been using the Convert Time Field tool in Python but it takes a very very LONG time to complete. I have found using Field Calculator is much much FASTER.
If you chose any other datetime format other one that requires you to specify the "Day" of the week in M, T, W... format, you would find that the Convert Time Field would take way less time, since it has to figure out what day of the week December 21st is.
It is an ugly process
import datetime
d = "12/21/2020" # ---- an example data, aka, your field
dt = datetime.datetime.strptime(d, "%m/%d/%Y") # make it a datetime thingy
dt.strftime('%A, %B %d %Y') # ---- reformatted separately, check python help
'Monday, December 21 2020' # --- you can put commas in and other stuff