I'm trying to copy the dates from a field called InspectionDate (date data type) to new field called CompletedDate (date data type) but I don't want the time stamp to be copied over. How can I copy just the date in a mm,dd,yyyy format using field calculator. For example copying 1/1/2016 12:00:00 AM to new field as 1/1/2016.
Storing time alone is not supported, but dates can be stored without time. I just happened to be doing this - I have a date field with date/time stamps and I only want date stamps. I used these field calculator settings - replace DATEFIELD with your field name.
Show Codeblock: checked
Pre-Logic Script Code:
def FindDate(date): if date is None: return None else: return date.split(" ").pop(0)
You can't remove the Hours/Minutes/Seconds while using the Date field type. You will have to convert to an alternative field type.
From ESRI on Working with Date Fields:
Enter dates in MM/DD/YYYY hh:mm:ss format
Regardless of how dates are displayed in the table, you can only enter dates in MM/DD/YYYY hh:mm:ss format, enclosed in single quotation marks. For example, to set a date field to 5:00PM on May 27, 2014, you would type '05/27/2014 05:00:00PM', '05/27/2014 5:00PM', or '05/27/2014 17:00:00' (24-hour clock). Storing time alone is not supported—time must always be a component of a date.
To correct I would suggest creating a string(text) field type as it will allow the format you are seeking of MM/DD/YYYY.
It is important to note that answers that work for ArcGIS Desktop/ArcMap will not work for ArcGIS Pro, and vice versa, because the Field Calculator (or Calculate Field in ArcGIS Pro) treats ArcGIS Date fields differently between the products. The other answers to this question work for ArcGIS Desktop/ArcMap because Field Calculator handles ArcGIS Date fields as Python
unicode, but they don't work for ArcGIS Pro because Calculate Field handles ArcGIS Date fields as Python
It is also important to note that ArcGIS Date data types (ArcGIS field data types - ArcGIS Pro | Documentation) are a date and time data type, so you can't "remove" the time from it. However, if you set the time to 00:00:00 then ArcGIS software will typically display only the date portion.
Since Field Calculator in ArcGIS Desktop/ArcMap retrieves and returns Python
unicode, it allows the ArcGIS Date to be manipulated using string methods like
# Parser/Expression Type: Python # Expression !Date_Field!.split() if !Date_Field! is not None else None
Using a Python Conditional Expression to handle SQL NULL, one can avoid having to use a Code Block and instead can put all the Python code in the Expression.
Since Calculate Field in ArcGIS Pro retrieves and returns Python
datetime.datetime, one must manipulate the ArcGIS Date using datetime methods.
# Parser/Expression Type: Python # Expression datetime.datetime(!Date_Field!.year, !Date_Field!.month, !Date_Field!.day) if !Date_Field! is not None else None
Your problem might be simpler than you think. Sometimes you may need to export your data to a different format before exploring much more complicated steps like field calculators:
A coverage or shapefile stores dates in a date field with this format: yyyy-mm-dd. A geodatabase formats the date as datetime yyyy-mm-dd hh:mm:ss AM or PM. Settings on your Windows system determine how the dates are displayed in ArcMap—M/d/yy, MM/dd/yy, yy/MM/dd, and so on. ArcMap uses the system short date format (numerical) for displaying dates